| 1: | <?php | 
| 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: |  | 
| 44: |  | 
| 45: |  | 
| 46: |  | 
| 47: |  | 
| 48: |  | 
| 49: | function smarty_function_mailto($params) | 
| 50: | { | 
| 51: | static $_allowed_encoding = array( | 
| 52: | 'javascript' => true, | 
| 53: | 'javascript_charcode' => true, | 
| 54: | 'hex' => true, | 
| 55: | 'none' => true | 
| 56: | ); | 
| 57: |  | 
| 58: | $extra = ''; | 
| 59: | if (empty($params[ 'address' ])) { | 
| 60: | trigger_error("mailto: missing 'address' parameter", E_USER_WARNING); | 
| 61: | return; | 
| 62: | } else { | 
| 63: | $address = $params[ 'address' ]; | 
| 64: | } | 
| 65: |  | 
| 66: | $text = $address; | 
| 67: |  | 
| 68: |  | 
| 69: |  | 
| 70: | $mail_parms = array(); | 
| 71: | foreach ($params as $var => $value) { | 
| 72: | switch ($var) { | 
| 73: | case 'cc': | 
| 74: | case 'bcc': | 
| 75: | case 'followupto': | 
| 76: | if (!empty($value)) { | 
| 77: | $mail_parms[] = $var . '=' . str_replace(array('%40', '%2C'), array('@', ','), rawurlencode($value)); | 
| 78: | } | 
| 79: | break; | 
| 80: | case 'subject': | 
| 81: | case 'newsgroups': | 
| 82: | $mail_parms[] = $var . '=' . rawurlencode($value); | 
| 83: | break; | 
| 84: | case 'extra': | 
| 85: | case 'text': | 
| 86: | $$var = $value; | 
| 87: |  | 
| 88: | default: | 
| 89: | } | 
| 90: | } | 
| 91: |  | 
| 92: | if ($mail_parms) { | 
| 93: | $address .= '?' . join('&', $mail_parms); | 
| 94: | } | 
| 95: | $encode = (empty($params[ 'encode' ])) ? 'none' : $params[ 'encode' ]; | 
| 96: | if (!isset($_allowed_encoding[ $encode ])) { | 
| 97: | trigger_error( | 
| 98: | "mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex", | 
| 99: | E_USER_WARNING | 
| 100: | ); | 
| 101: | return; | 
| 102: | } | 
| 103: |  | 
| 104: | $flags = ENT_QUOTES; | 
| 105: | if (defined('ENT_SUBSTITUTE') && defined('ENT_HTML401')) { | 
| 106: | $flags |= ENT_SUBSTITUTE | ENT_HTML401; | 
| 107: | } | 
| 108: |  | 
| 109: | $string = '<a href="mailto:' . htmlspecialchars($address, $flags, Smarty::$_CHARSET) . | 
| 110: | '" ' . $extra . '>' . htmlspecialchars($text, $flags, Smarty::$_CHARSET) . '</a>'; | 
| 111: |  | 
| 112: | if ($encode === 'javascript') { | 
| 113: | $js_encode = ''; | 
| 114: | for ($x = 0, $_length = strlen($string); $x < $_length; $x++) { | 
| 115: | $js_encode .= '%' . bin2hex($string[ $x ]); | 
| 116: | } | 
| 117: | return '<script type="text/javascript">document.write(unescape(\'' . $js_encode . '\'))</script>'; | 
| 118: | } elseif ($encode === 'javascript_charcode') { | 
| 119: | for ($x = 0, $_length = strlen($string); $x < $_length; $x++) { | 
| 120: | $ord[] = ord($string[ $x ]); | 
| 121: | } | 
| 122: | return '<script type="text/javascript">document.write(String.fromCharCode(' . implode(',', $ord) . '))</script>'; | 
| 123: | } elseif ($encode === 'hex') { | 
| 124: | preg_match('!^(.*)(\?.*)$!', $address, $match); | 
| 125: | if (!empty($match[ 2 ])) { | 
| 126: | trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.", E_USER_WARNING); | 
| 127: | return; | 
| 128: | } | 
| 129: | $address_encode = ''; | 
| 130: | for ($x = 0, $_length = strlen($address); $x < $_length; $x++) { | 
| 131: | if (preg_match('!\w!' . Smarty::$_UTF8_MODIFIER, $address[ $x ])) { | 
| 132: | $address_encode .= '%' . bin2hex($address[ $x ]); | 
| 133: | } else { | 
| 134: | $address_encode .= $address[ $x ]; | 
| 135: | } | 
| 136: | } | 
| 137: | $text_encode = ''; | 
| 138: | for ($x = 0, $_length = strlen($text); $x < $_length; $x++) { | 
| 139: | $text_encode .= '&#x' . bin2hex($text[ $x ]) . ';'; | 
| 140: | } | 
| 141: | $mailto = "mailto:"; | 
| 142: | return '<a href="' . $mailto . $address_encode . '" ' . $extra . '>' . $text_encode . '</a>'; | 
| 143: | } else { | 
| 144: |  | 
| 145: | return $string; | 
| 146: | } | 
| 147: | } | 
| 148: |  |