-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplugin.php
43 lines (36 loc) · 1.02 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class pluginEncodeMail extends Plugin {
public function init()
{
}
public function pageBegin()
{
global $page;
$temp = $this->htmlizeEmails($page->content());
$page->setField('content', $temp);
}
//Finds email addresses in content
//Replace every email address with HTML-ASCII Code
private function htmlizeEmails($text)
{
preg_match_all('/([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})/', $text, $potentialEmails, PREG_SET_ORDER);
$potentialEmailsCount = count($potentialEmails);
for ($i = 0; $i < $potentialEmailsCount; $i++) {
if (filter_var($potentialEmails[$i][0], FILTER_VALIDATE_EMAIL)) {
$ascii_mail_address = $this->encode_email_address($potentialEmails[$i][0]);
$text = str_replace($potentialEmails[$i][0], $ascii_mail_address, $text);
}
}
return $text;
}
//Encode a given string in HTML-ASCII
private function encode_email_address($email)
{
$result = '';
for ($i = 0; $i < strlen($email); $i++)
{
$result .= '&#'.ord($email[$i]).';';
}
return $result;
}
}