Advertisement
Guest User

Untitled

a guest
Apr 27th, 2011
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.13 KB | None | 0 0
  1. class Gform_Pgp_Encrypt extends GFCommon{
  2.            
  3.             private $path;
  4.            
  5.             public function __construct(){
  6.                 $this->path = '';
  7.                 add_filter( 'gform_disable_admin_notification', array( &$this, 'overwrite_admin_notification' ), 10, 3 );        
  8.             }
  9.            
  10.             public function overwrite_admin_notification($is_disabled, $form, $entry){
  11.                
  12.                 self::send_crypt_admin_notification( $form, $entry );
  13.                 return true;
  14.             }
  15.            
  16.             public static function send_crypt_admin_notification($form, $lead){
  17.                 $form_id = $form["id"];
  18.        
  19.                 //handling admin notification email
  20.                 $subject = GFCommon::replace_variables(rgget("subject", $form["notification"]), $form, $lead, false, false);
  21.                 $message = GFCommon::replace_variables(rgget("message", $form["notification"]), $form, $lead, false, false, !rgget("disableAutoformat", $form["notification"]));
  22.                 $message = do_shortcode($message);
  23.                 $message = self::encrypt_message($message);
  24.                 $from = rgempty("fromField", $form["notification"]) ? rgget("from", $form["notification"]) : rgget($form["notification"]["fromField"], $lead);
  25.        
  26.                 if(rgempty("fromNameField", $form["notification"])){
  27.                     $from_name = rgget("fromName", $form["notification"]);
  28.                 }
  29.                 else{
  30.                     $field = RGFormsModel::get_field($form, rgget("fromNameField", $form["notification"]));
  31.                     $value = RGFormsModel::get_lead_field_value($lead, $field);
  32.                     $from_name = GFCommon::get_lead_field_display($field, $value);
  33.                 }
  34.        
  35.                 $replyTo = rgempty("replyToField", $form["notification"]) ? rgget("replyTo", $form["notification"]): rgget($form["notification"]["replyToField"], $lead);
  36.        
  37.                 if(rgempty("routing", $form["notification"])){
  38.                     $email_to = rgget("to", $form["notification"]);
  39.                 }
  40.                 else{
  41.                     $email_to = array();
  42.        
  43.                     foreach($form["notification"]["routing"] as $routing){
  44.        
  45.                         $source_field = RGFormsModel::get_field($form, $routing["fieldId"]);
  46.                         $field_value = RGFormsModel::get_field_value($source_field, array());
  47.                         $is_value_match = is_array($field_value) ? in_array($routing["value"], $field_value) : $field_value == $routing["value"];
  48.        
  49.                         if( ($routing["operator"] == "is" && $is_value_match ) || ($routing["operator"] == "isnot" && !$is_value_match) )
  50.                             $email_to[] = $routing["email"];
  51.                     }
  52.        
  53.                     $email_to = join(",", $email_to);
  54.                 }
  55.        
  56.                 //Running through variable replacement
  57.                 $email_to = GFCommon::replace_variables($email_to, $form, $lead, false, false);
  58.                 $from = GFCommon::replace_variables($from, $form, $lead, false, false);
  59.                 $bcc = GFCommon::replace_variables(rgget("bcc", $form["notification"]), $form, $lead, false, false);
  60.                 $reply_to = GFCommon::replace_variables($replyTo, $form, $lead, false, false);
  61.                 $from_name = GFCommon::replace_variables($from_name, $form, $lead, false, false);
  62.        
  63.                 //Filters the admin notification email to address. Allows users to change email address before notification is sent
  64.                 $to = apply_filters("gform_notification_email_{$form_id}" , apply_filters("gform_notification_email", $email_to, $lead), $lead);
  65.        
  66.                 self::send_email($from, $to, $bcc, $replyTo, $subject, $message, $from_name);
  67.             }
  68.            
  69.             private static function send_email($from, $to, $bcc, $reply_to, $subject, $message, $from_name=""){
  70.  
  71.                 //invalid to email address or no content. can't send email
  72.                 if(!GFCommon::is_valid_email($to) || (empty($subject) && empty($message)))
  73.                     return;
  74.        
  75.                 if(!GFCommon::is_valid_email($from))
  76.                     $from = get_bloginfo("admin_email");
  77.        
  78.                 //invalid from address. can't send email
  79.                 if(!GFCommon::is_valid_email($from))
  80.                     return;
  81.        
  82.                 $name = empty($from_name) ? $from : $from_name;
  83.                 $headers = "From: \"$name\" <$from> \r\n";
  84.                 $headers .= GFCommon::is_valid_email($reply_to) ? "Reply-To: $reply_to\r\n" :"";
  85.                 $headers .= GFCommon::is_valid_email($bcc) ? "Bcc: $bcc\r\n" :"";
  86.                 $headers .= 'Content-type: text/html; charset=' . get_option('blog_charset') . "\r\n";
  87.        
  88.                 $result = wp_mail($to, $subject, $message, $headers);
  89.             }
  90.            
  91.             private function encrypt_message($message){
  92.                 // will encrypt message here.
  93.                 return $message;
  94.             }
  95.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement