libs/plugins/function.mailto.php Quellcode

function.mailto.php
gehe zur Dokumentation dieser Datei
1 <?php
51 function smarty_function_mailto($params)
52 {
53  static $_allowed_encoding = array('javascript' => true, 'javascript_charcode' => true, 'hex' => true, 'none' => true);
54  $extra = '';
55 
56  if (empty($params['address'])) {
57  trigger_error("mailto: missing 'address' parameter", E_USER_WARNING);
58 
59  return;
60  } else {
61  $address = $params['address'];
62  }
63 
64  $text = $address;
65  // netscape and mozilla do not decode %40 (@) in BCC field (bug?)
66  // so, don't encode it.
67  $search = array('%40', '%2C');
68  $replace = array('@', ',');
69  $mail_parms = array();
70  foreach ($params as $var => $value) {
71  switch ($var) {
72  case 'cc':
73  case 'bcc':
74  case 'followupto':
75  if (!empty($value)) {
76  $mail_parms[] = $var . '=' . str_replace($search, $replace, rawurlencode($value));
77  }
78  break;
79 
80  case 'subject':
81  case 'newsgroups':
82  $mail_parms[] = $var . '=' . rawurlencode($value);
83  break;
84 
85  case 'extra':
86  case 'text':
87  $$var = $value;
88 
89  default:
90  }
91  }
92 
93  if ($mail_parms) {
94  $address .= '?' . join('&', $mail_parms);
95  }
96 
97  $encode = (empty($params['encode'])) ? 'none' : $params['encode'];
98  if (!isset($_allowed_encoding[$encode])) {
99  trigger_error("mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex", E_USER_WARNING);
100 
101  return;
102  }
103  // FIXME: (rodneyrehm) document.write() excues me what? 1998 has passed!
104  if ($encode == 'javascript') {
105  $string = 'document.write(\'<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>\');';
106 
107  $js_encode = '';
108  for ($x = 0, $_length = strlen($string); $x < $_length; $x ++) {
109  $js_encode .= '%' . bin2hex($string[$x]);
110  }
111 
112  return '<script type="text/javascript">eval(unescape(\'' . $js_encode . '\'))</script>';
113  } elseif ($encode == 'javascript_charcode') {
114  $string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
115 
116  for ($x = 0, $y = strlen($string); $x < $y; $x ++) {
117  $ord[] = ord($string[$x]);
118  }
119 
120  $_ret = "<script type=\"text/javascript\" language=\"javascript\">\n"
121  . "{document.write(String.fromCharCode("
122  . implode(',', $ord)
123  . "))"
124  . "}\n"
125  . "</script>\n";
126 
127  return $_ret;
128  } elseif ($encode == 'hex') {
129  preg_match('!^(.*)(\?.*)$!', $address, $match);
130  if (!empty($match[2])) {
131  trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.", E_USER_WARNING);
132 
133  return;
134  }
135  $address_encode = '';
136  for ($x = 0, $_length = strlen($address); $x < $_length; $x ++) {
137  if (preg_match('!\w!' . Smarty::$_UTF8_MODIFIER, $address[$x])) {
138  $address_encode .= '%' . bin2hex($address[$x]);
139  } else {
140  $address_encode .= $address[$x];
141  }
142  }
143  $text_encode = '';
144  for ($x = 0, $_length = strlen($text); $x < $_length; $x ++) {
145  $text_encode .= '&#x' . bin2hex($text[$x]) . ';';
146  }
147 
148  $mailto = "&#109;&#97;&#105;&#108;&#116;&#111;&#58;";
149 
150  return '<a href="' . $mailto . $address_encode . '" ' . $extra . '>' . $text_encode . '</a>';
151  } else {
152  // no encoding
153  return '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
154  }
155 }




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.