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.  * This file is released under the LGPL
  20.  * "GNU Lesser General Public License"
  21.  * More information can be found here:
  22.  * {@link http://www.gnu.org/copyleft/lesser.html}
  23.  *
  24.  * @author     Jordi Boggiano <j.boggiano@seld.be>
  25.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  26.  * @license    http://www.gnu.org/copyleft/lesser.html  GNU Lesser General Public License
  27.  * @link       http://dwoo.org/
  28.  * @version    0.9.1
  29.  * @date       2008-05-30
  30.  * @package    Dwoo
  31.  */
  32. function Dwoo_Plugin_mailto(Dwoo $dwoo$address$text=null$subject=null$encode=null$cc=null$bcc=null$newsgroups=null$followupto=null$extra=null)
  33. {
  34.     if (empty($address)) {
  35.         return '';
  36.     }
  37.     if (empty($text)) {
  38.         $text $address;
  39.     }
  40.  
  41.     // build address string
  42.     $address .= '?';
  43.  
  44.     if (!empty($subject)) {
  45.         $address .= 'subject='.rawurlencode($subject).'&';
  46.     }
  47.     if (!empty($cc)) {
  48.         $address .= 'cc='.rawurlencode($cc).'&';
  49.     }
  50.     if (!empty($bcc)) {
  51.         $address .= 'bcc='.rawurlencode($bcc).'&';
  52.     }
  53.     if (!empty($newsgroup)) {
  54.         $address .= 'newsgroups='.rawurlencode($newsgroups).'&';
  55.     }
  56.     if (!empty($followupto)) {
  57.         $address .= 'followupto='.rawurlencode($followupto).'&';
  58.     }
  59.  
  60.     $address rtrim($address'?&');
  61.  
  62.     // output
  63.     switch($encode)
  64.     {
  65.  
  66.     case 'none':
  67.     case null:
  68.         return '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
  69.  
  70.     case 'js':
  71.     case 'javascript':
  72.         $str 'document.write(\'<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>\');';
  73.         $len strlen($str);
  74.  
  75.         $out '';
  76.         for ($i=0$i<$len$i++{
  77.             $out .= '%'.bin2hex($str[$i]);
  78.         }
  79.         return '<script type="text/javascript">eval(unescape(\''.$out.'\'));</script>';
  80.  
  81.         break;
  82.     case 'javascript_charcode':
  83.     case 'js_charcode':
  84.     case 'jscharcode':
  85.     case 'jschar':
  86.         $str '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
  87.         $len strlen($str);
  88.  
  89.         $out '<script type="text/javascript">'."\n<!--\ndocument.write(String.fromCharCode(";
  90.         for ($i=0$i<$len$i++{
  91.             $out .= ord($str[$i]).',';
  92.         }
  93.         return rtrim($out','"));\n-->\n</script>\n";
  94.  
  95.         break;
  96.  
  97.     case 'hex':
  98.         if (strpos($address'?'!== false{
  99.             return $dwoo->triggerError('Mailto: Hex encoding is not possible with extra attributes, use one of : <em>js, jscharcode or none</em>.'E_USER_WARNING);
  100.         }
  101.  
  102.         $out '<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;';
  103.         $len strlen($address);
  104.         for ($i=0$i<$len$i++{
  105.             if (preg_match('#\w#'$address[$i])) {
  106.                 $out .= '%'.bin2hex($address[$i]);
  107.             else {
  108.                 $out .= $address[$i];
  109.             }
  110.         }
  111.         $out .= '" '.$extra.'>';
  112.         $len strlen($text);
  113.         for ($i=0$i<$len$i++{
  114.             $out .= '&#x'.bin2hex($text[$i]);
  115.         }
  116.         return $out.'</a>';
  117.  
  118.     default:
  119.         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);
  120.  
  121.     }
  122. }

Documentation generated on Sun, 07 Sep 2008 23:57:54 +0200 by phpDocumentor 1.4.0