5 Modification information for LGPL compliance
7 r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync
9 r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover
11 r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex
13 r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3 tags and updated the build system
15 r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
17 r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
19 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
21 r8230 - 2005-10-03 17:47:19 -0700 (Mon, 03 Oct 2005) - majed - Added Sugar_Smarty to the code tree.
35 * Smarty {mailto} function plugin
40 * Purpose: automate mailto address link creation, and optionally
43 * - address = e-mail address
44 * - text = (optional) text to display, default is address
45 * - encode = (optional) can be one of:
46 * * none : no encoding (default)
47 * * javascript : encode with javascript
48 * * javascript_charcode : encode with javascript charcode
49 * * hex : encode with hexidecimal (no javascript)
50 * - cc = (optional) address(es) to carbon copy
51 * - bcc = (optional) address(es) to blind carbon copy
52 * - subject = (optional) e-mail subject
53 * - newsgroups = (optional) newsgroup(s) to post to
54 * - followupto = (optional) address(es) to follow up to
55 * - extra = (optional) extra tags for the href link
59 * {mailto address="me@domain.com"}
60 * {mailto address="me@domain.com" encode="javascript"}
61 * {mailto address="me@domain.com" encode="hex"}
62 * {mailto address="me@domain.com" subject="Hello to you!"}
63 * {mailto address="me@domain.com" cc="you@domain.com,they@domain.com"}
64 * {mailto address="me@domain.com" extra='class="mailto"'}
66 * @link http://smarty.php.net/manual/en/language.function.mailto.php {mailto}
67 * (Smarty online manual)
69 * @author Monte Ohrt <monte at ohrt dot com>
70 * @author credits to Jason Sweat (added cc, bcc and subject functionality)
75 function smarty_function_mailto($params, &$smarty)
79 if (empty($params['address'])) {
80 $smarty->trigger_error("mailto: missing 'address' parameter");
83 $address = $params['address'];
88 // netscape and mozilla do not decode %40 (@) in BCC field (bug?)
89 // so, don't encode it.
90 $mail_parms = array();
91 foreach ($params as $var=>$value) {
97 $mail_parms[] = $var.'='.str_replace('%40','@',rawurlencode($value));
102 $mail_parms[] = $var.'='.rawurlencode($value);
113 $mail_parm_vals = '';
114 for ($i=0; $i<count($mail_parms); $i++) {
115 $mail_parm_vals .= (0==$i) ? '?' : '&';
116 $mail_parm_vals .= $mail_parms[$i];
118 $address .= $mail_parm_vals;
120 $encode = (empty($params['encode'])) ? 'none' : $params['encode'];
121 if (!in_array($encode,array('javascript','javascript_charcode','hex','none')) ) {
122 $smarty->trigger_error("mailto: 'encode' parameter must be none, javascript or hex");
126 if ($encode == 'javascript' ) {
127 $string = 'document.write(\'<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>\');';
130 for ($x=0; $x < strlen($string); $x++) {
131 $js_encode .= '%' . bin2hex($string[$x]);
134 return '<script type="text/javascript">eval(unescape(\''.$js_encode.'\'))</script>';
136 } elseif ($encode == 'javascript_charcode' ) {
137 $string = '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
139 for($x = 0, $y = strlen($string); $x < $y; $x++ ) {
140 $ord[] = ord($string[$x]);
143 $_ret = "<script type=\"text/javascript\" language=\"javascript\">\n";
145 $_ret .= "{document.write(String.fromCharCode(";
146 $_ret .= implode(',',$ord);
150 $_ret .= "</script>\n";
155 } elseif ($encode == 'hex') {
157 preg_match('!^(.*)(\?.*)$!',$address,$match);
158 if(!empty($match[2])) {
159 $smarty->trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.");
162 $address_encode = '';
163 for ($x=0; $x < strlen($address); $x++) {
164 if(preg_match('!\w!',$address[$x])) {
165 $address_encode .= '%' . bin2hex($address[$x]);
167 $address_encode .= $address[$x];
171 for ($x=0; $x < strlen($text); $x++) {
172 $text_encode .= '&#x' . bin2hex($text[$x]).';';
175 $mailto = "mailto:";
176 return '<a href="'.$mailto.$address_encode.'" '.$extra.'>'.$text_encode.'</a>';
180 return '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
186 /* vim: set expandtab: */