From a6c179d56973e382205c8583568d635c37f814c8 Mon Sep 17 00:00:00 2001 From: Nathan Kinkade Date: Tue, 27 Aug 2019 13:05:48 -0600 Subject: Updates smarty to v3.1.33. --- lib/smarty-3.1.33/plugins/function.mailto.php | 137 ++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 lib/smarty-3.1.33/plugins/function.mailto.php (limited to 'lib/smarty-3.1.33/plugins/function.mailto.php') diff --git a/lib/smarty-3.1.33/plugins/function.mailto.php b/lib/smarty-3.1.33/plugins/function.mailto.php new file mode 100644 index 0000000..27351df --- /dev/null +++ b/lib/smarty-3.1.33/plugins/function.mailto.php @@ -0,0 +1,137 @@ + + * @author credits to Jason Sweat (added cc, bcc and subject functionality) + * + * @param array $params parameters + * + * @return string + */ +function smarty_function_mailto($params) +{ + static $_allowed_encoding = + array('javascript' => true, 'javascript_charcode' => true, 'hex' => true, 'none' => true); + $extra = ''; + if (empty($params[ 'address' ])) { + trigger_error("mailto: missing 'address' parameter", E_USER_WARNING); + return; + } else { + $address = $params[ 'address' ]; + } + $text = $address; + // netscape and mozilla do not decode %40 (@) in BCC field (bug?) + // so, don't encode it. + $search = array('%40', '%2C'); + $replace = array('@', ','); + $mail_parms = array(); + foreach ($params as $var => $value) { + switch ($var) { + case 'cc': + case 'bcc': + case 'followupto': + if (!empty($value)) { + $mail_parms[] = $var . '=' . str_replace($search, $replace, rawurlencode($value)); + } + break; + case 'subject': + case 'newsgroups': + $mail_parms[] = $var . '=' . rawurlencode($value); + break; + case 'extra': + case 'text': + $$var = $value; + // no break + default: + } + } + if ($mail_parms) { + $address .= '?' . join('&', $mail_parms); + } + $encode = (empty($params[ 'encode' ])) ? 'none' : $params[ 'encode' ]; + if (!isset($_allowed_encoding[ $encode ])) { + trigger_error( + "mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex", + E_USER_WARNING + ); + return; + } + // FIXME: (rodneyrehm) document.write() excues me what? 1998 has passed! + if ($encode === 'javascript') { + $string = 'document.write(\'' . $text . '\');'; + $js_encode = ''; + for ($x = 0, $_length = strlen($string); $x < $_length; $x++) { + $js_encode .= '%' . bin2hex($string[ $x ]); + } + return ''; + } elseif ($encode === 'javascript_charcode') { + $string = '' . $text . ''; + for ($x = 0, $y = strlen($string); $x < $y; $x++) { + $ord[] = ord($string[ $x ]); + } + $_ret = "\n"; + return $_ret; + } elseif ($encode === 'hex') { + preg_match('!^(.*)(\?.*)$!', $address, $match); + if (!empty($match[ 2 ])) { + trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.", E_USER_WARNING); + return; + } + $address_encode = ''; + for ($x = 0, $_length = strlen($address); $x < $_length; $x++) { + if (preg_match('!\w!' . Smarty::$_UTF8_MODIFIER, $address[ $x ])) { + $address_encode .= '%' . bin2hex($address[ $x ]); + } else { + $address_encode .= $address[ $x ]; + } + } + $text_encode = ''; + for ($x = 0, $_length = strlen($text); $x < $_length; $x++) { + $text_encode .= '&#x' . bin2hex($text[ $x ]) . ';'; + } + $mailto = "mailto:"; + return '' . $text_encode . ''; + } else { + // no encoding + return '' . $text . ''; + } +} -- cgit v1.2.3