54 if (empty($params[
'address'])) {
55 $smarty->trigger_error(
"mailto: missing 'address' parameter");
58 $address = $params[
'address'];
65 $search = array(
'%40',
'%2C');
66 $replace = array(
'@',
',');
67 $mail_parms = array();
68 foreach ($params as
$var=>$value) {
74 $mail_parms[] =
$var.
'='.str_replace($search,$replace,rawurlencode($value));
79 $mail_parms[] =
$var.
'='.rawurlencode($value);
91 for (
$i=0;
$i<count($mail_parms);
$i++) {
92 $mail_parm_vals .= (0==
$i) ?
'?' :
'&';
93 $mail_parm_vals .= $mail_parms[
$i];
95 $address .= $mail_parm_vals;
97 $encode = (empty($params[
'encode'])) ?
'none' : $params[
'encode'];
98 if (!in_array($encode,array(
'javascript',
'javascript_charcode',
'hex',
'none')) ) {
99 $smarty->trigger_error(
"mailto: 'encode' parameter must be none, javascript or hex");
103 if ($encode ==
'javascript' ) {
104 $string =
'document.write(\'<a href="mailto:'.$address.
'" '.$extra.
'>'.$text.
'</a>\');';
107 for ($x=0; $x < strlen($string); $x++) {
108 $js_encode .=
'%' . bin2hex($string[$x]);
111 return '<script type="text/javascript">eval(unescape(\''.$js_encode.
'\'))</script>
';
113 } elseif ($encode == 'javascript_charcode
' ) {
114 $string = '<a href=
"mailto:'.$address.'" '.$extra.'>
'.$text.'</a>
';
116 for($x = 0, $y = strlen($string); $x < $y; $x++ ) {
117 $ord[] = ord($string[$x]);
120 $_ret = "<script type=\"text/javascript\" language=\"javascript\">\n";
122 $_ret .= "{document.write(String.fromCharCode(";
123 $_ret .= implode(',
',$ord);
127 $_ret .= "</script>\n";
132 } elseif ($encode == 'hex
') {
134 preg_match('!^(.*)(\?.*)$!
',$address,$match);
135 if(!empty($match[2])) {
136 $smarty->trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.");
139 $address_encode = '';
140 for ($x=0; $x < strlen($address); $x++) {
141 if(preg_match('!\w!
',$address[$x])) {
142 $address_encode .= '%
' . bin2hex($address[$x]);
144 $address_encode .= $address[$x];
148 for ($x=0; $x < strlen($text); $x++) {
149 $text_encode .= '&#x
' . bin2hex($text[$x]).';
';
152 $mailto = "mailto:";
153 return '<a href=
"'.$mailto.$address_encode.'" '.$extra.'>
'.$text_encode.'</a>
';
157 return '<a href=
"mailto:'.$address.'" '.$extra.'>
'.$text.'</a>
';
163 /* vim: set expandtab: */