format('d.m.Y'), $text);
$text = preg_replace('/\{\{until\}\}/', $until->format('d.m.Y'), $text);
return $text;
}
public static function isHoliday($config) {
if(!array_key_exists('holidays', $config)) {
throw new Exception('holidays missing in config');
}
if(!array_key_exists('from', $config['holidays']) || !array_key_exists('until', $config['holidays'])) {
throw new Exception('from/until missing in holidays config');
}
$from = DateTime::createFromFormat('Y-m-d', $config['holidays']['from']);
$from->setTime(0, 0);
$until = DateTime::createFromFormat('Y-m-d', $config['holidays']['until']);
$until->setTime(23, 59, 59);
$today = new DateTime();
$today->setTime(0, 0);
$dialogShowFrom = clone $from;
if(array_key_exists('before', $config['holidays']) && !empty($config['holidays']['before'])) {
$dialogShowFrom->sub(new DateInterval('P' . $config['holidays']['before']));
}
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 .= '' . htmlspecialchars($reversed) . '';
return sprintf(
'%s',
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(
'%s',
htmlspecialchars($baseClass),
htmlspecialchars($user),
htmlspecialchars($domain),
htmlspecialchars($tld),
$style,
htmlspecialchars($reversed)
);
}
}