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

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:16 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.