/** * This function uses the {@link obfuscate_email()} and {@link obfuscate_text()} * to generate a fully obfuscated email link, ready to use. * * @param string $email The email address to display * @param string $label The text to displayed as hyperlink to $email * @param boolean $dimmed If true then use css class 'dimmed' for hyperlink * @return string The obfuscated mailto link */ function obfuscate_mailto($email, $label = '', $dimmed = false) { if (empty($label)) { $label = $email; } if ($dimmed) { $title = get_string('emaildisable'); $dimmed = ' class="dimmed"'; } else { $title = ''; $dimmed = ''; } return sprintf("<a href=\"%s:%s\" {$dimmed} title=\"{$title}\">%s</a>", obfuscate_text('mailto'), obfuscate_email($email), obfuscate_text($label)); }
/** * This function uses the {@link obfuscate_email()} and {@link obfuscate_text()} * to generate a fully obfuscated email link, ready to use. * * @param string $email The email address to display * @param string $label The text to displayed as hyperlink to $email * @param boolean $dimmed If true then use css class 'dimmed' for hyperlink * @param string $subject The subject of the email in the mailto link * @param string $body The content of the email in the mailto link * @return string The obfuscated mailto link */ function obfuscate_mailto($email, $label = '', $dimmed = false, $subject = '', $body = '') { if (empty($label)) { $label = $email; } $label = obfuscate_text($label); $email = obfuscate_email($email); $mailto = obfuscate_text('mailto'); $url = new moodle_url("mailto:{$email}"); $attrs = array(); if (!empty($subject)) { $url->param('subject', format_string($subject)); } if (!empty($body)) { $url->param('body', format_string($body)); } // Use the obfuscated mailto. $url = preg_replace('/^mailto/', $mailto, $url->out()); if ($dimmed) { $attrs['title'] = get_string('emaildisable'); $attrs['class'] = 'dimmed'; } return html_writer::link($url, $label, $attrs); }
public function test_obfuscate_text() { $text = 'Žluťoučký koníček 32131'; $obfuscated = obfuscate_text($text); $this->assertNotSame($text, $obfuscated); $back = core_text::entities_to_utf8($obfuscated, true); $this->assertSame($text, $back); }
function alter_email($matches) { return $matches[1] . obfuscate_text($matches[2]) . $matches[3]; }