[phpMP-CVS] CVS: phpMP/includes/plugins function.mailto.php,NONE,1.1 outputfilter.trimwhitespace.php
Status: Pre-Alpha
Brought to you by:
heimidal
From: Brian R. <hei...@us...> - 2003-02-06 02:11:08
|
Update of /cvsroot/phpmp/phpMP/includes/plugins In directory sc8-pr-cvs1:/tmp/cvs-serv4545 Added Files: function.mailto.php outputfilter.trimwhitespace.php Log Message: Update to Smarty 2.4.0. --- NEW FILE: function.mailto.php --- <?php /* * Smarty plugin * ------------------------------------------------------------- * Type: function * Name: mailto * Version: 1.2 * Date: May 21, 2002 * Author: Monte Ohrt <mo...@is...> * Credits: Jason Sweat (added cc, bcc and subject functionality) * Purpose: automate mailto address link creation, and optionally * encode them. * Input: address = e-mail address * text = (optional) text to display, default is address * encode = (optional) can be one of: * none : no encoding (default) * javascript : encode with javascript * hex : encode with hexidecimal (no javascript) * cc = (optional) address(es) to carbon copy * bcc = (optional) address(es) to blind carbon copy * subject = (optional) e-mail subject * newsgroups = (optional) newsgroup(s) to post to * followupto = (optional) address(es) to follow up to * extra = (optional) extra tags for the href link * * Examples: {mailto address="me...@do..."} * {mailto address="me...@do..." encode="javascript"} * {mailto address="me...@do..." encode="hex"} * {mailto address="me...@do..." subject="Hello to you!"} * {mailto address="me...@do..." cc="yo...@do...,th...@do..."} * {mailto address="me...@do..." extra='class="mailto"'} * ------------------------------------------------------------- */ function smarty_function_mailto($params, &$smarty) { extract($params); if (empty($address)) { $smarty->trigger_error("mailto: missing 'address' parameter"); return; } if (empty($text)) { $text = $address; } // netscape and mozilla do not decode %40 (@) in BCC field (bug?) // so, don't encode it. $mail_parms = array(); if (!empty($cc)) { $mail_parms[] = 'cc='.str_replace('%40','@',rawurlencode($cc)); } if (!empty($bcc)) { $mail_parms[] = 'bcc='.str_replace('%40','@',rawurlencode($bcc)); } if (!empty($subject)) { $mail_parms[] = 'subject='.rawurlencode($subject); } if (!empty($newsgroups)) { $mail_parms[] = 'newsgroups='.rawurlencode($newsgroups); } if (!empty($followupto)) { $mail_parms[] = 'followupto='.str_replace('%40','@',rawurlencode($followupto)); } for ($i=0; $i<count($mail_parms); $i++) { $mail_parm_vals .= (0==$i) ? '?' : '&'; $mail_parm_vals .= $mail_parms[$i]; } $address .= $mail_parm_vals; if (empty($encode)) { $encode = 'none'; } elseif (!in_array($encode,array('javascript','hex','none')) ) { $smarty->trigger_error("mailto: 'encode' parameter must be none, javascript or hex"); return; } if ($encode == 'javascript' ) { $string = 'document.write(\'<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>\');'; for ($x=0; $x < strlen($string); $x++) { $js_encode .= '%' . bin2hex($string[$x]); } return '<SCRIPT language="javascript">eval(unescape(\''.$js_encode.'\'))</SCRIPT>'; } elseif ($encode == 'hex') { preg_match('!^(.*)(\?.*)$!',$address,$match); if(!empty($match[2])) { $smarty->trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript."); return; } for ($x=0; $x < strlen($address); $x++) { if(preg_match('!\w!',$address[$x])) { $address_encode .= '%' . bin2hex($address[$x]); } else { $address_encode .= $address[$x]; } } for ($x=0; $x < strlen($text); $x++) { $text_encode .= '&#x' . bin2hex($text[$x]).';'; } return '<a href="mailto:'.$address_encode.'" '.$extra.'>'.$text_encode.'</a>'; } else { // no encoding return '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>'; } } /* vim: set expandtab: */ ?> --- NEW FILE: outputfilter.trimwhitespace.php --- <?php /* * Smarty plugin * ------------------------------------------------------------- * File: outputfilter.trimwhitespace.php * Type: outputfilter * Name: trimwhitespace * Version: 1.3 * Date: Jan 25, 2003 * Purpose: trim leading white space and blank lines from * template source after it gets interpreted, cleaning * up code and saving bandwidth. Does not affect * <PRE></PRE> and <SCRIPT></SCRIPT> blocks. * Install: Drop into the plugin directory, call * $smarty->load_filter('output','trimwhitespace'); * from application. * Author: Monte Ohrt <mo...@is...> * Contribs: Lars Noschinski <la...@us...> * ------------------------------------------------------------- */ function smarty_outputfilter_trimwhitespace($source, &$smarty) { // Pull out the script blocks preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match); $_script_blocks = $match[0]; $source = preg_replace("!<script[^>]+>.*?</script>!is", '@@@SMARTY:TRIM:SCRIPT@@@', $source); // Pull out the pre blocks preg_match_all("!<pre>.*?</pre>!is", $source, $match); $_pre_blocks = $match[0]; $source = preg_replace("!<pre>.*?</pre>!is", '@@@SMARTY:TRIM:PRE@@@', $source); // Pull out the textarea blocks preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source, $match); $_textarea_blocks = $match[0]; $source = preg_replace("!<textarea[^>]+>.*?</textarea>!is", '@@@SMARTY:TRIM:TEXTAREA@@@', $source); // remove all leading spaces, tabs and carriage returns NOT // preceeded by a php close tag. $source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source)); // replace script blocks foreach($_script_blocks as $curr_block) { $source = preg_replace("!@@@SMARTY:TRIM:SCRIPT@@@!",$curr_block,$source,1); } // replace pre blocks foreach($_pre_blocks as $curr_block) { $source = preg_replace("!@@@SMARTY:TRIM:PRE@@@!",$curr_block,$source,1); } // replace textarea blocks foreach($_textarea_blocks as $curr_block) { $source = preg_replace("!@@@SMARTY:TRIM:TEXTAREA@@@!",$curr_block,$source,1); } return $source; } ?> |