Source for file mailto.php

Documentation is available at mailto.php

  1. <?php
  2.  
  3. /**
  4.  * Outputs a mailto link with optional spam-proof (okay probably not) encoding
  5.  * <pre>
  6.  *  * address : target email address
  7.  *  * text : display text to show for the link, defaults to the address if not provided
  8.  *  * subject : the email subject
  9.  *  * encode : one of the available encoding (none, js, jscharcode or hex)
  10.  *  * cc : address(es) to carbon copy, comma separated
  11.  *  * bcc : address(es) to blind carbon copy, comma separated
  12.  *  * newsgroups : newsgroup(s) to post to, comma separated
  13.  *  * followupto : address(es) to follow up, comma separated
  14.  *  * extra : additional attributes to add to the &lt;a&gt; tag
  15.  * </pre>
  16.  * This software is provided 'as-is', without any express or implied warranty.
  17.  * In no event will the authors be held liable for any damages arising from the use of this software.
  18.  *
  19.  * @author     Jordi Boggiano <j.boggiano@seld.be>
  20.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  21.  * @license    http://dwoo.org/LICENSE   Modified BSD License
  22.  * @link       http://dwoo.org/
  23.  * @version    1.1.0
  24.  * @date       2009-07-18
  25.  * @package    Dwoo
  26.  */
  27. function Dwoo_Plugin_mailto(Dwoo $dwoo$address$text=null$subject=null$encode=null$cc=null$bcc=null$newsgroups=null$followupto=null$extra=null)
  28. {
  29.     if (empty($address)) {
  30.         return '';
  31.     }
  32.     if (empty($text)) {
  33.         $text $address;
  34.     }
  35.  
  36.     // build address string
  37.     $address .= '?';
  38.  
  39.     if (!empty($subject)) {
  40.         $address .= 'subject='.rawurlencode($subject).'&';
  41.     }
  42.     if (!empty($cc)) {
  43.         $address .= 'cc='.rawurlencode($cc).'&';
  44.     }
  45.     if (!empty($bcc)) {
  46.         $address .= 'bcc='.rawurlencode($bcc).'&';
  47.     }
  48.     if (!empty($newsgroups)) {
  49.         $address .= 'newsgroups='.rawurlencode($newsgroups).'&';
  50.     }
  51.     if (!empty($followupto)) {
  52.         $address .= 'followupto='.rawurlencode($followupto).'&';
  53.     }
  54.  
  55.     $address rtrim($address'?&');
  56.  
  57.     // output
  58.     switch($encode)
  59.     {
  60.  
  61.     case 'none':
  62.     case null:
  63.         return '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
  64.  
  65.     case 'js':
  66.     case 'javascript':
  67.         $str 'document.write(\'<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>\');';
  68.         $len strlen($str);
  69.  
  70.         $out '';
  71.         for ($i=0$i<$len$i++{
  72.             $out .= '%'.bin2hex($str[$i]);
  73.         }
  74.         return '<script type="text/javascript">eval(unescape(\''.$out.'\'));</script>';
  75.  
  76.         break;
  77.     case 'javascript_charcode':
  78.     case 'js_charcode':
  79.     case 'jscharcode':
  80.     case 'jschar':
  81.         $str '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
  82.         $len strlen($str);
  83.  
  84.         $out '<script type="text/javascript">'."\n<!--\ndocument.write(String.fromCharCode(";
  85.         for ($i=0$i<$len$i++{
  86.             $out .= ord($str[$i]).',';
  87.         }
  88.         return rtrim($out','"));\n-->\n</script>\n";
  89.  
  90.         break;
  91.  
  92.     case 'hex':
  93.         if (strpos($address'?'!== false{
  94.             return $dwoo->triggerError('Mailto: Hex encoding is not possible with extra attributes, use one of : <em>js, jscharcode or none</em>.'E_USER_WARNING);
  95.         }
  96.  
  97.         $out '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;';
  98.         $len strlen($address);
  99.         for ($i=0$i<$len$i++{
  100.             if (preg_match('#\w#'$address[$i])) {
  101.                 $out .= '%'.bin2hex($address[$i]);
  102.             else {
  103.                 $out .= $address[$i];
  104.             }
  105.         }
  106.         $out .= '" '.$extra.'>';
  107.         $len strlen($text);
  108.         for ($i=0$i<$len$i++{
  109.             $out .= '&#x'.bin2hex($text[$i]);
  110.         }
  111.         return $out.'</a>';
  112.  
  113.     default:
  114.         return $dwoo->triggerError('Mailto: <em>encode</em> argument is invalid, it must be one of : <em>none (= no value), js, js_charcode or hex</em>'E_USER_WARNING);
  115.  
  116.     }
  117. }

Documentation generated on Sun, 07 Feb 2010 17:53:52 +0000 by phpDocumentor 1.4.0