Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Gform_Pgp_Encrypt extends GFCommon{
- private $path;
- public function __construct(){
- $this->path = '';
- add_filter( 'gform_disable_admin_notification', array( &$this, 'overwrite_admin_notification' ), 10, 3 );
- }
- public function overwrite_admin_notification($is_disabled, $form, $entry){
- self::send_crypt_admin_notification( $form, $entry );
- return true;
- }
- public static function send_crypt_admin_notification($form, $lead){
- $form_id = $form["id"];
- //handling admin notification email
- $subject = GFCommon::replace_variables(rgget("subject", $form["notification"]), $form, $lead, false, false);
- $message = GFCommon::replace_variables(rgget("message", $form["notification"]), $form, $lead, false, false, !rgget("disableAutoformat", $form["notification"]));
- $message = do_shortcode($message);
- $message = self::encrypt_message($message);
- $from = rgempty("fromField", $form["notification"]) ? rgget("from", $form["notification"]) : rgget($form["notification"]["fromField"], $lead);
- if(rgempty("fromNameField", $form["notification"])){
- $from_name = rgget("fromName", $form["notification"]);
- }
- else{
- $field = RGFormsModel::get_field($form, rgget("fromNameField", $form["notification"]));
- $value = RGFormsModel::get_lead_field_value($lead, $field);
- $from_name = GFCommon::get_lead_field_display($field, $value);
- }
- $replyTo = rgempty("replyToField", $form["notification"]) ? rgget("replyTo", $form["notification"]): rgget($form["notification"]["replyToField"], $lead);
- if(rgempty("routing", $form["notification"])){
- $email_to = rgget("to", $form["notification"]);
- }
- else{
- $email_to = array();
- foreach($form["notification"]["routing"] as $routing){
- $source_field = RGFormsModel::get_field($form, $routing["fieldId"]);
- $field_value = RGFormsModel::get_field_value($source_field, array());
- $is_value_match = is_array($field_value) ? in_array($routing["value"], $field_value) : $field_value == $routing["value"];
- if( ($routing["operator"] == "is" && $is_value_match ) || ($routing["operator"] == "isnot" && !$is_value_match) )
- $email_to[] = $routing["email"];
- }
- $email_to = join(",", $email_to);
- }
- //Running through variable replacement
- $email_to = GFCommon::replace_variables($email_to, $form, $lead, false, false);
- $from = GFCommon::replace_variables($from, $form, $lead, false, false);
- $bcc = GFCommon::replace_variables(rgget("bcc", $form["notification"]), $form, $lead, false, false);
- $reply_to = GFCommon::replace_variables($replyTo, $form, $lead, false, false);
- $from_name = GFCommon::replace_variables($from_name, $form, $lead, false, false);
- //Filters the admin notification email to address. Allows users to change email address before notification is sent
- $to = apply_filters("gform_notification_email_{$form_id}" , apply_filters("gform_notification_email", $email_to, $lead), $lead);
- self::send_email($from, $to, $bcc, $replyTo, $subject, $message, $from_name);
- }
- private static function send_email($from, $to, $bcc, $reply_to, $subject, $message, $from_name=""){
- //invalid to email address or no content. can't send email
- if(!GFCommon::is_valid_email($to) || (empty($subject) && empty($message)))
- return;
- if(!GFCommon::is_valid_email($from))
- $from = get_bloginfo("admin_email");
- //invalid from address. can't send email
- if(!GFCommon::is_valid_email($from))
- return;
- $name = empty($from_name) ? $from : $from_name;
- $headers = "From: \"$name\" <$from> \r\n";
- $headers .= GFCommon::is_valid_email($reply_to) ? "Reply-To: $reply_to\r\n" :"";
- $headers .= GFCommon::is_valid_email($bcc) ? "Bcc: $bcc\r\n" :"";
- $headers .= 'Content-type: text/html; charset=' . get_option('blog_charset') . "\r\n";
- $result = wp_mail($to, $subject, $message, $headers);
- }
- private function encrypt_message($message){
- // will encrypt message here.
- return $message;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement