1 |
1546
|
Luisehahne
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* QuickSkin Extension mailtoencode
|
4 |
|
|
* Protects email address from being scanned by spam bots
|
5 |
|
|
* and optionally builds full mailto: link
|
6 |
|
|
*
|
7 |
|
|
* Usage Example 1:
|
8 |
|
|
* Content: $template->assign('AUTHOR', 'yourname@yourdomain.com' );
|
9 |
|
|
* Template: Author: {mailtoencode:AUTHOR}
|
10 |
|
|
* Result: Author: <a href="mailto:yourname@yourdomain.com">yourname@yourdomain.com</a>
|
11 |
|
|
*
|
12 |
|
|
* Usage Example 2 (Email address only):
|
13 |
|
|
* Template: Author: {mailtoencode:"yourname@yourdomain.com"}
|
14 |
|
|
* Result: Author: <a href="mailto:yourname@yourdomain.com">yourname@yourdomain.com</a>
|
15 |
|
|
*
|
16 |
|
|
* Usage Example 3 (Email address and name):
|
17 |
|
|
* Template: Author: {mailtoencode:"yourname@yourdomain.com","Your Name"}
|
18 |
|
|
* Result: Author: <a href="mailto:yourname@yourdomain.com">Your Name</a>
|
19 |
|
|
*
|
20 |
|
|
* Usage Example 4 (Email address and name, encode set to true, and class name):
|
21 |
|
|
* Template: Author: {mailtoencode:"yourname@yourdomain.com","Your Name",true,'white'}
|
22 |
|
|
* Result: Author: <a href="mailto:yourname@yourdomain.com" class="white">Your Name</a>
|
23 |
|
|
*
|
24 |
|
|
* Usage Example 5 (Email address and name, encode set to true, class name and style defined):
|
25 |
|
|
* Template: Author: {mailtoencode:"yourname@yourdomain.com","Your Name",true,'white','font-size:18px;'}
|
26 |
|
|
* Result: Author: <a href="mailto:yourname@yourdomain.com" class="white" style="font-size:18px;">Your Name</a>
|
27 |
|
|
*
|
28 |
|
|
* Usage Example 6 (Email address and name, encode set to true, no class name and style defined):
|
29 |
|
|
* Template: Author: {mailtoencode:"yourname@yourdomain.com","Your Name",true,'','font-size:18px;'}
|
30 |
|
|
* Result: Author: <a href="mailto:yourname@yourdomain.com" style="font-size:18px;">Your Name</a>
|
31 |
|
|
*
|
32 |
|
|
* @author Andy Prevost andy@codeworxtech.com
|
33 |
|
|
*/
|
34 |
|
|
|
35 |
|
|
if(!function_exists('str_split')){
|
36 |
|
|
function str_split($text, $split = 1){
|
37 |
|
|
$array = array();
|
38 |
|
|
for($i=0; $i < strlen($text); $i++){
|
39 |
|
|
$key = NULL;
|
40 |
|
|
for ($j = 0; $j < $split; $j++){
|
41 |
|
|
$key .= $text[$i];
|
42 |
|
|
}
|
43 |
|
|
array_push($array, $key);
|
44 |
|
|
}
|
45 |
|
|
return $array;
|
46 |
|
|
}
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
function qx_mailtoencode ($emailAddy,$text='',$buildLink=true,$class='',$style='') {
|
50 |
|
|
if ( $buildLink ) {
|
51 |
|
|
// mailto: portion
|
52 |
|
|
$obfuscatedMailTo = '';
|
53 |
|
|
$mailto = "mailto:";
|
54 |
|
|
$length = strlen($mailto);
|
55 |
|
|
for ($i = 0; $i < $length; $i++) {
|
56 |
|
|
$obfuscatedMailTo .= "&#" . ord($mailto[$i]);
|
57 |
|
|
}
|
58 |
|
|
// END - mailto: portion
|
59 |
|
|
$emailLink = '<a href="';
|
60 |
|
|
$emailLink .= $obfuscatedMailTo;
|
61 |
|
|
}
|
62 |
|
|
$emailLink .= obfuscate($emailAddy);
|
63 |
|
|
if ( $buildLink ) {
|
64 |
|
|
$emailLink .= '"';
|
65 |
|
|
if ( trim($class) != '' ) {
|
66 |
|
|
$emailLink .= ' class="' . $class . '"';
|
67 |
|
|
}
|
68 |
|
|
if ( trim($style) != '' ) {
|
69 |
|
|
$emailLink .= ' style="' . $style . '"';
|
70 |
|
|
}
|
71 |
|
|
$emailLink .= '>';
|
72 |
|
|
if ( trim($text) != '' ) {
|
73 |
|
|
$newText = trim($text);
|
74 |
|
|
$newText = str_replace('@','@',$newText);
|
75 |
|
|
$newText = str_replace('.','.',$newText);
|
76 |
|
|
$emailLink .= $newText;
|
77 |
|
|
} else {
|
78 |
|
|
$newText = trim($emailAddy);
|
79 |
|
|
$newText = str_replace('@','@',$newText);
|
80 |
|
|
$newText = str_replace('.','.',$newText);
|
81 |
|
|
$emailLink .= $newText;
|
82 |
|
|
}
|
83 |
|
|
$emailLink .= "</a>";
|
84 |
|
|
}
|
85 |
|
|
return $emailLink;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
function obfuscate($text) { // NOTE: Uses function str_split
|
89 |
|
|
preg_match_all("/[-a-z0-9\._]+@[-a-z0-9\._]+\.[a-z]{2,4}/", $text, $emails);
|
90 |
|
|
$patterns = array();
|
91 |
|
|
$replacements = array();
|
92 |
|
|
foreach($emails[0] as $email) {
|
93 |
|
|
if(!in_array("/$email/", $patterns)) {
|
94 |
|
|
$obfuscated = '';
|
95 |
|
|
foreach(str_split($email) as $char) {
|
96 |
|
|
$obfuscated .= '&#'.ord($char).';';
|
97 |
|
|
}
|
98 |
|
|
$patterns[] = "/$email/";
|
99 |
|
|
$replacements[] = $obfuscated;
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
|
|
$text = preg_replace($patterns, $replacements, $text);
|
103 |
|
|
return $text;
|
104 |
|
|
}
|