Exemplo n.º 1
0
 protected function _mymail($data)
 {
     if (!defined('MYMAIL_DIR')) {
         return array('success' => false, 'message' => __('myMail Newsletters not exists!.', DHVC_FORM));
     }
     $form_id = $_REQUEST['dhvc_form'];
     $lists = dhvc_get_post_meta($form_id, '_mymail', array());
     $double_opt_in = dhvc_get_post_meta($form_id, '_mymail_double_opt_in', 0) == '1' ? true : false;
     $userdata['firstname'] = isset($data['firstname']) ? trim(preg_replace('/\\s*\\[[^)]*\\]/', '', $data['firstname'])) : '';
     $userdata['lastname'] = isset($data['lastname']) ? trim(preg_replace('/\\s*\\[[^)]*\\]/', '', $data['lastname'])) : '';
     $email = isset($data['email']) ? $data['email'] : '';
     if (!is_email($email)) {
         return array('success' => false, 'message' => __('The email address isn\'t correct.', DHVC_FORM));
     }
     $ret = mymail_subscribe($email, $userdata, $lists, $double_opt_in, true);
     if (!$ret) {
         return array('success' => false, 'message' => __('Not Subscribe to our Newsletters!', DHVC_FORM));
     } else {
         return array('success' => true, 'message' => __('Subscribe to our Newsletters successful!', DHVC_FORM));
     }
 }
Exemplo n.º 2
0
function formcraft_submit()
{
    error_reporting(0);
    global $errors, $id;
    $conten = file_get_contents('php://input');
    $conten = explode('&', $conten);
    $nos = sizeof($conten);
    $title = $_POST['title'];
    $id = intval(preg_replace("/[^0-9,.]/", "", $_POST['id']));
    $i = 0;
    while ($i < $nos) {
        $cont = explode('=', $conten["{$i}"]);
        $content[$cont[0]] = $cont[1];
        $content_ex = explode('_', $cont[0]);
        if (!($content_ex[0] == 'id') && !($content_ex[0] == 'action')) {
            $new[$i]['label'] = $content_ex[0];
            $new[$i]['value'] = urldecode($cont[1]);
            $new[$i]['type'] = $content_ex[1];
            $new[$i]['validation'] = $content_ex[2];
            $new[$i]['required'] = $content_ex[3];
            $new[$i]['min'] = $content_ex[4];
            $new[$i]['max'] = $content_ex[5];
            $new[$i]['tooltip'] = $content_ex[6];
            $new[$i]['custom'] = $content_ex[7];
            $new[$i]['custom2'] = $content_ex[8];
            $new[$i]['custom3'] = $content_ex[9];
            $new[$i]['custom4'] = $content_ex[10];
            $new[$i]['custom5'] = $content_ex[11];
        }
        $i++;
    }
    /* Get Form Options */
    global $wpdb, $table_subs, $table_builder, $table_info;
    $qry = $wpdb->get_results("SELECT * FROM {$table_builder} WHERE id = '{$id}'", 'ARRAY_A');
    foreach ($qry as $row) {
        $con = stripslashes($row['con']);
        $title = stripslashes($row['name']);
        $rec = stripslashes($row['recipients']);
    }
    $con = json_decode($con, 1);
    $rec = formcraft_parse_emails($rec);
    if (isset($_POST['emails'])) {
        $rec = array_merge($rec, formcraft_parse_emails($_POST['emails']));
    }
    /* Apply filter to recipients before sending so it can be handle externally  */
    $rec = apply_filters('formcraft_presend_recipients', $rec, $id);
    /* Run the Validation Functions */
    $i = 0;
    $ar_inc = 1;
    while ($i < $nos) {
        if ($new[$i]['custom'] == 'autoreply') {
            $autoreply[$ar_inc] = $new[$i]['value'];
            $ar_inc++;
        }
        $new[$i]['custom3'] = 'zz' . $new[$i]['custom3'];
        if ($new[$i]['type'] == 'email' && $new[$i]['custom4'] == 'notif') {
            $rec[$new[$i]['value']] = '';
        }
        if ($new[$i]['type'] == 'email' && $new[$i]['custom5'] == 'notif') {
            $rec[$new[$i]['value']] = '';
        }
        if ($new[$i]['label'] == 'files') {
            $filePath = dirname(__FILE__) . '/file-upload/server/content/files/' . substr($new[$i]['value'], strrpos($new[$i]['value'], '/') + 1);
            if (filesize($filePath) / 1048576 < 100) {
                $attachments[] = $filePath;
            }
        }
        /* Prepare List for MailChimp */
        if ($new[$i]['type'] == 'email' && strpos($new[$i]['custom3'], 'm') == true) {
            $mc_add[] = $new[$i]['value'];
        }
        /* Prepare List for AWeber */
        if ($new[$i]['type'] == 'email' && strpos($new[$i]['custom3'], 'a') == true) {
            $aw_add[] = $new[$i]['value'];
        }
        /* Prepare List for Campaign Monitor */
        if ($new[$i]['type'] == 'email' && strpos($new[$i]['custom3'], 'c') == true) {
            $campaign_add[] = $new[$i]['value'];
        }
        /* Prepare List for Campaign Monitor */
        if ($new[$i]['type'] == 'email' && strpos($new[$i]['custom3'], 'g') == true) {
            $gr_add[] = $new[$i]['value'];
        }
        /* Prepare List for MyMail */
        if ($new[$i]['type'] == 'email' && $new[$i]['custom4'] == 'true') {
            $mm_add[] = $new[$i]['value'];
            $mm++;
        }
        /* Prepare List of Custom Variables for MC or MM */
        if ($new[$i]['type'] != 'email' && isset($new[$i]['custom'])) {
            if (!empty($new[$i]['value'])) {
                $custom_var[$new[$i]['custom']] = $new[$i]['value'];
            }
        }
        if ($new[$i]['custom2'] == 'replyto') {
            $replyto = $new[$i]['value'];
        }
        if ($new[$i]['type'] == 'upload' && $new[$i]['value'] == '0') {
            $new[$i]['value'] = null;
        }
        formcraft_no_val($new[$i]['value'], $new[$i]['required'], $new[$i]['min'], $new[$i]['max'], $new[$i]['tooltip'], $con[0]);
        if (function_exists('formcraft_' . $new[$i]['validation'])) {
            $fncall = 'formcraft_' . $new[$i]['validation'];
            $fncall($new[$i]['value'], $new[$i]['validation'], $new[$i]['required'], $new[$i]['min'], $new[$i]['max'], $new[$i]['tooltip'], $con[0]);
        }
        $i++;
    }
    if (sizeof($errors)) {
        if ($con[0]['error_gen'] != null) {
            $errors['errors'] = $con[0]['error_gen'];
        } else {
            $errors['errors'] = '';
        }
        $errors = json_encode($errors);
        echo $errors;
    } else {
        global $wpdb, $table_subs, $table_builder;
        $qry = $wpdb->get_results("SELECT * FROM {$table_builder} WHERE id = '{$id}'", 'ARRAY_A');
        foreach ($qry as $row) {
            $con = stripslashes($row['con']);
        }
        $con = json_decode($con, 1);
        $sender_name = $con[0]['from_name'];
        $sender_email = $con[0]['from_email'];
        $success_sent = 0;
        /* Add to MailChimp */
        if (defined('FORMCRAFT_ADD')) {
            if ($con[0]['mc_double'] == 'true') {
                $con[0]['mc_double'] = true;
            } else {
                $con[0]['mc_double'] = false;
            }
            if ($con[0]['mc_welcome'] == 'true') {
                $con[0]['mc_welcome'] = true;
            } else {
                $con[0]['mc_welcome'] = false;
            }
            if ($con[0]['mc_list'] && isset($mc_add) && function_exists('mailchimp_fc')) {
                mailchimp_fc($mc_add, $custom_var, $con[0]['mc_list'], $con[0]['mc_double'], $con[0]['mc_welcome']);
            }
            if ($con[0]['aw_list'] && isset($aw_add) && function_exists('aweber_fc')) {
                aweber_fc($aw_add, $custom_var, $con[0]['aw_list']);
            }
            if ($con[0]['campaign_list'] && isset($campaign_add) && function_exists('campaign_fc')) {
                campaign_fc($campaign_add, $custom_var, $con[0]['campaign_list']);
            }
            if ($con[0]['gr_list'] && isset($gr_add) && function_exists('gr_fc')) {
                gr_fc($gr_add, $custom_var, $con[0]['gr_list']);
            }
        }
        /* Add to MyMail */
        if (isset($con[0]['mm_list']) && defined('MYMAIL_VERSION')) {
            $template = 'notification.html';
            foreach ($mm_add as $mm_email) {
                mymail_subscribe($mm_email, $custom_var, $con[0]['mm_list'], NULL, true, NULL, $template);
            }
        }
        /* Make the Email */
        $label_style = "padding: 4px 8px 4px 0px; margin: 0; width: 180px; font-size: 13px; font-weight: bold";
        $value_style = "padding: 4px 8px 4px 0px; margin: 0; font-size: 13px";
        $divider_style = "padding: 10px 8px 4px 0px; margin: 0; font-size: 16px; font-weight: bold; border-bottom: 1px solid #ddd";
        $i = 0;
        $att = 1;
        $email_body = '';
        while ($i < $nos) {
            $new[$i]['value'] = nl2br($new[$i]['value']);
            if ($new[$i]['label'] != 'files') {
                $new[$i]['label'] = urldecode($new[$i]['label']);
                $new[$i]['value'] = $new[$i]['value'];
            }
            if (!empty($new[$i]['type']) && !($new[$i]['type'] == 'captcha') && !($new[$i]['type'] == 'hidden') && !($new[$i]['label'] == 'files') && !($new[$i]['label'] == 'divider') && !($new[$i]['type'] == 'radio') && !($new[$i]['type'] == 'check') && !($new[$i]['type'] == 'smiley') && !($new[$i]['type'] == 'stars') && !($new[$i]['type'] == 'matrix')) {
                $new[$i]['value'] = str_replace('<br />', 'LINEBREAK', $new[$i]['value']);
                $new[$i]['value'] = htmlentities($new[$i]['value'], ENT_COMPAT | ENT_HTML401, 'utf-8');
                $new[$i]['value'] = str_replace('LINEBREAK', '</br>', $new[$i]['value']);
                $email_body .= "<tr><td style='{$label_style}'> " . $new[$i]['label'] . "</td><td style='{$value_style}'>" . $new[$i]['value'] . "</td></tr>";
            } else {
                if ($new[$i]['label'] == 'files') {
                    $email_body .= "<tr><td style='{$label_style}'>Attachment({$att})</td><td style='{$value_style}'><a href='" . $new[$i]['value'] . "'>" . $new[$i]['value'] . "</a></td></tr>";
                    $att++;
                } else {
                    if ($new[$i]['label'] == 'divider') {
                        $email_body .= "</table><table style='border: 0px; color: #333; width: 100%'><tr><td style='{$divider_style}'>" . $new[$i]['value'] . "</td></tr></table><table>";
                    } else {
                        if ($new[$i]['type'] == 'hidden' && $new[$i]['label'] == 'location') {
                            $location = $new[$i]['value'];
                        } else {
                            if ($new[$i]['type'] == 'hidden') {
                                $email_body .= "<tr><td style='{$label_style}'> " . $new[$i]['label'] . "</td><td style='{$value_style}'>" . $new[$i]['value'] . "</td></tr>";
                            } else {
                                if ($new[$i]['type'] == 'radio' || $new[$i]['type'] == 'check' || $new[$i]['type'] == 'smiley' || $new[$i]['type'] == 'stars' || $new[$i]['type'] == 'matrix') {
                                    if ($new[$i]['value'] == true) {
                                        $email_body .= "<tr><td style='{$label_style}'>" . $new[$i]['label'] . "</td><td style='{$value_style}'> " . $new[$i]['value'] . "</td></tr>";
                                    }
                                }
                            }
                        }
                    }
                }
            }
            $i++;
        }
        $email_body = "<table cellpadding='0' cellspacing='0' style='border: 0px; color: #333; width: 100%'>" . $email_body . "</table>";
        $con[0]['email_body'] = nl2br($con[0]['email_body']);
        if (isset($con[0]['email_body']) && $con[0]['email_body'] != '') {
            $email_body = str_replace("[Form Content]", $email_body, $con[0]['email_body']);
        } else {
            $email_body = "<h3 style='margin-bottom: 20px'>{$title}</h3>{$email_body}";
        }
        $email_body = str_replace("[Form Name]", $title, $email_body);
        $email_body = str_replace("[URL]", $location, $email_body);
        $email_body = str_replace("[form_name]", $title, $email_body);
        $subIDRow = $wpdb->get_results("SELECT MAX(id) FROM {$table_subs}", ARRAY_A);
        $subID = intval($subIDRow[0]['MAX(id)']) + 1;
        $pattern = '/\\[.*?\\]/';
        preg_match_all($pattern, $con['0']['autoreply'], $matches);
        foreach ($new as $field) {
            foreach ($matches[0] as $match) {
                $match2 = str_replace('[', '', $match);
                $match2 = str_replace(']', '', $match2);
                if ($field['label'] == $match2) {
                    $con['0']['autoreply'] = str_replace($match, $field['value'], $con['0']['autoreply']);
                }
            }
        }
        $pattern = '/\\[.*?\\]/';
        preg_match_all($pattern, $email_body, $matches);
        foreach ($new as $field) {
            foreach ($matches[0] as $match) {
                $match2 = str_replace('[', '', $match);
                $match2 = str_replace(']', '', $match2);
                if ($field['label'] == $match2) {
                    $email_body = str_replace($match, $field['value'], $email_body);
                }
            }
        }
        preg_match_all($pattern, $con['0']['autoreply_s'], $matches);
        foreach ($new as $field) {
            foreach ($matches[0] as $match) {
                $match2 = str_replace('[', '', $match);
                $match2 = str_replace(']', '', $match2);
                if ($field['label'] == $match2) {
                    $con['0']['autoreply_s'] = str_replace($match, $field['value'], $con['0']['autoreply_s']);
                }
            }
        }
        preg_match_all($pattern, $con[0]['email_sub'], $matches);
        foreach ($new as $field) {
            foreach ($matches[0] as $match) {
                $match2 = str_replace('[', '', $match);
                $match2 = str_replace(']', '', $match2);
                if ($field['label'] == $match2) {
                    $con[0]['email_sub'] = str_replace($match, $field['value'], $con[0]['email_sub']);
                }
            }
        }
        $sender_name = $con[0]['mail_type'] == 'smtp' ? $con[0]['smtp_name'] : $con[0]['from_name'];
        $sender_email = $con[0]['mail_type'] == 'smtp' ? $con[0]['smtp_email'] : $con[0]['from_email'];
        preg_match_all($pattern, $sender_name, $matches);
        foreach ($new as $field) {
            foreach ($matches[0] as $match) {
                $match2 = str_replace('[', '', $match);
                $match2 = str_replace(']', '', $match2);
                if ($field['label'] == $match2) {
                    $sender_name = str_replace($match, $field['value'], $sender_name);
                }
            }
        }
        preg_match_all($pattern, $sender_email, $matches);
        foreach ($new as $field) {
            foreach ($matches[0] as $match) {
                $match2 = str_replace('[', '', $match);
                $match2 = str_replace(']', '', $match2);
                if ($field['label'] == $match2) {
                    $sender_email = str_replace($match, $field['value'], $sender_email);
                }
            }
        }
        $sender_email = filter_var($sender_email, FILTER_VALIDATE_EMAIL) ? $sender_email : '';
        $autoreply_email = filter_var($con[0]['autoreply_email'], FILTER_VALIDATE_EMAIL) ? $con[0]['autoreply_email'] : $sender_email;
        $autoreply_name = $con[0]['autoreply_name'] ? $con[0]['autoreply_name'] : $sender_name;
        if (isset($con[0]['autoreply']) && $con[0]['autoreply'] != '') {
            $con[0]['autoreply'] = str_replace("[Form Content]", $email_body, $con[0]['autoreply']);
        }
        $con[0]['email_sub'] = str_replace("[form_name]", $title, $con[0]['email_sub']);
        $con[0]['autoreply_s'] = str_replace("[form_name]", $title, $con[0]['autoreply_s']);
        $con[0]['autoreply'] = str_replace("[form_name]", $title, $con[0]['autoreply']);
        $con[0]['email_sub'] = str_replace("[Form Name]", $title, $con[0]['email_sub']);
        $con[0]['autoreply_s'] = str_replace("[Form Name]", $title, $con[0]['autoreply_s']);
        $con[0]['autoreply'] = str_replace("[Form Name]", $title, $con[0]['autoreply']);
        $con[0]['email_sub'] = str_replace("[ID]", $subID, $con[0]['email_sub']);
        $con[0]['autoreply_s'] = str_replace("[ID]", $subID, $con[0]['autoreply_s']);
        $con[0]['autoreply'] = str_replace("[ID]", $subID, $con[0]['autoreply']);
        $con[0]['email_sub'] = str_replace("{{form_name}}", $title, $con[0]['email_sub']);
        $con[0]['autoreply_s'] = str_replace("{{form_name}}", $title, $con[0]['autoreply_s']);
        $con[0]['autoreply'] = str_replace("{{form_name}}", $title, $con[0]['autoreply']);
        $email_subject = $con[0]['email_sub'];
        $sender_name = empty($sender_name) ? get_bloginfo('name') : $sender_name;
        $sender_email = empty($sender_email) ? get_bloginfo('admin_email') : $sender_email;
        /* SwiftMailer Main */
        require_once 'php/swift/lib/swift_required.php';
        if ($con[0]['smtp_port'] == '') {
            $con[0]['smtp_port'] = $con[0]['if_ssl'] == 'tls' ? 587 : 465;
            $con[0]['smtp_port'] = $con[0]['if_ssl'] == 'false' || $con[0]['if_ssl'] == '' ? 25 : $con[0]['smtp_port'];
        }
        if ($con[0]['mail_type'] == 'smtp') {
            if ($con[0]['if_ssl'] == 'ssl' || $con[0]['if_ssl'] == 'tls') {
                $transport = Swift_SmtpTransport::newInstance($con[0]['smtp_host'], $con[0]['smtp_port'], $con[0]['if_ssl'])->setUsername($con[0]['smtp_username'])->setPassword($con[0]['smtp_pass']);
            } else {
                $transport = Swift_SmtpTransport::newInstance($con[0]['smtp_host'], $con[0]['smtp_port'])->setUsername($con[0]['smtp_username'])->setPassword($con[0]['smtp_pass']);
            }
        } else {
            $transport = Swift_MailTransport::newInstance();
        }
        if ($replyto == false) {
            $replyto = $sender_email;
        }
        $sent = 0;
        foreach ($rec as $emailTo => $nameTo) {
            $mailer = Swift_Mailer::newInstance($transport);
            $message = Swift_Message::newInstance()->setSubject($email_subject)->setFrom(array($sender_email => $sender_name))->setTo(array($emailTo => $nameTo))->setBody($email_body, 'text/html');
            if (filter_var($replyto, FILTER_VALIDATE_EMAIL)) {
                $message->setReplyTo(array($replyto));
            }
            if (isset($attachments) && count($attachments) > 0) {
                foreach ($attachments as $value) {
                    $message->attach(Swift_Attachment::fromPath($value));
                }
            }
            try {
                if ($mailer->send($message, $failures)) {
                    $sent++;
                }
            } catch (\Exception $e) {
                //echo $e->getMessage();
            }
        }
        if ($autoreply) {
            foreach ($autoreply as $user_email) {
                if (empty($user_email)) {
                    continue;
                }
                $mailer = Swift_Mailer::newInstance($transport);
                $message = Swift_Message::newInstance()->setSubject($con['0']['autoreply_s'])->setFrom(array($autoreply_email => $autoreply_name))->setReplyTo(array($autoreply_email => $autoreply_name))->setTo(array($user_email))->setBody("<div style='white-space: pre-line'>" . $con['0']['autoreply'] . "</div>", 'text/html');
                try {
                    $mailer->send($message, $failures);
                } catch (\Exception $e) {
                    //echo $e->getMessage();
                }
            }
        }
        $new_json = json_encode($new);
        global $wpdb, $table_subs, $table_builder, $table_info;
        $date = date('d M Y (H:i)');
        $date2 = date('Y-m-d');
        $temp1 = $wpdb->query("SELECT * FROM {$table_info} WHERE time = '{$date2}' AND id = {$id} ");
        if ($temp1 >= 1) {
            $wpdb->query("UPDATE {$table_info} SET submissions = submissions + 1 WHERE id = {$id}  AND time = '{$date2}' ");
        } else {
            $temp2 = $wpdb->insert($table_info, array('time' => $date2, 'views' => 0, 'submissions' => 1, 'id' => $id));
        }
        $rows_affected = $wpdb->insert($table_subs, array('content' => $new_json, 'seen' => NULL, 'added' => $date, 'form_id' => $id));
        $result['done'] = $rows_affected;
        /* Display Success Message if Form Submission Updated in DataBase */
        if ($rows_affected) {
            if (isset($_POST['multi']) && $_POST['multi'] == 'false') {
                setcookie('fcwp', $_COOKIE['fcwp'] . ',' . $id, time() + 60 * 60 * 24 * 365, '/');
            }
            $error['sent'] = "true";
            $error['msg'] = "Message Sent";
            if (isset($con[0]['redirect']) && !empty($con[0]['redirect'])) {
                $error['redirect'] = $con[0]['redirect'];
            }
            $wpdb->query("UPDATE {$table_builder} SET\n                submits = submits + 1\n                WHERE id = '{$id}'");
            if (isset($con[0]['success_msg'])) {
                $error['msg'] = $con[0]['success_msg'];
            }
            echo json_encode($error);
        } else {
            $error['sent'] = "false";
            $error['msg'] = "The message could not be sent";
            if (isset($con[0]['failed_msg'])) {
                $error['msg'] = $con[0]['failed_msg'];
            }
            echo json_encode($error);
        }
    }
    die;
}
 public function indeed_myMailSubscribe($listId, $e_mail)
 {
     $userdata = array('firstname' => '', 'lastname' => '');
     if (function_exists('mymail_subscribe')) {
         $return = mymail_subscribe($e_mail, $userdata, array($listId), 0);
         if (!is_wp_error($return)) {
             return 1;
         } else {
             return 0;
         }
     } else {
         return 0;
     }
 }
function snp_popup_submit()
{
    global $wpdb;
    $result = array();
    $errors = array();
    $_POST['email'] = trim($_POST['email']);
    if (isset($_POST['name'])) {
        $_POST['name'] = trim($_POST['name']);
    }
    if (!snp_is_valid_email($_POST['email'])) {
        $errors['email'] = 1;
    }
    if (isset($_POST['name']) && !$_POST['name']) {
        $errors['name'] = 1;
    }
    $post_id = intval($_POST['popup_ID']);
    if ($post_id) {
        $POPUP_META = get_post_meta($post_id);
    }
    $cf_data = array();
    if (isset($POPUP_META['snp_cf']) && $post_id) {
        $cf = unserialize($POPUP_META['snp_cf'][0]);
        if (isset($cf) && is_array($cf)) {
            foreach ($cf as $f) {
                if (isset($f['name'])) {
                    if (strpos($f['name'], '[')) {
                        $f['name'] = substr($f['name'], 0, strpos($f['name'], '['));
                    }
                    if (!empty($_POST[$f['name']])) {
                        $cf_data[$f['name']] = $_POST[$f['name']];
                    }
                }
                if (isset($f['required']) && $f['required'] == 'Yes' && !$cf_data[$f['name']]) {
                    $errors[$f['name']] = 1;
                }
            }
        }
    }
    if (count($errors) > 0) {
        $result['Errors'] = $errors;
        $result['Ok'] = false;
    } else {
        $Done = 0;
        if (!empty($_POST['name'])) {
            $names = snp_detect_names($_POST['name']);
        } else {
            $names = array('first' => '', 'last' => '');
        }
        $api_error_msg = '';
        if (snp_get_option('ml_manager') == 'directmail') {
            require_once SNP_DIR_PATH . '/include/directmail/class.directmail.php';
            $form_id = snp_get_option('ml_dm_form_id');
            if ($form_id) {
                $api = new DMSubscribe();
                $retval = $api->submitSubscribeForm($form_id, $_POST['email'], $error_message);
                if ($retval) {
                    $Done = 1;
                } else {
                    // Error... Send by email?
                    $api_error_msg = $error_message;
                }
            }
        } elseif (snp_get_option('ml_manager') == 'sendy') {
            $list_id = $POPUP_META['snp_ml_sendy_list'][0];
            if (!$list_id) {
                $list_id = snp_get_option('ml_sendy_list');
            }
            if ($list_id) {
                $options = array('list' => $list_id, 'boolean' => 'true');
                $args['email'] = $_POST['email'];
                if (!empty($_POST['name'])) {
                    $args['name'] = $_POST['name'];
                }
                if (count($cf_data) > 0) {
                    $args = array_merge($args, (array) $cf_data);
                }
                $content = array_merge($args, $options);
                $postdata = http_build_query($content);
                $ch = curl_init(snp_get_option('ml_sendy_url') . '/subscribe');
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
                $api_result = curl_exec($ch);
                curl_close($ch);
                if (strval($api_result) == 'true' || strval($api_result) == '1' || strval($api_result) == 'Already subscribed.') {
                    $Done = 1;
                } else {
                    $api_error_msg = $api_result;
                }
            }
        } elseif (snp_get_option('ml_manager') == 'mailchimp') {
            require_once SNP_DIR_PATH . '/include/mailchimp/Mailchimp.php';
            $ml_mc_list = $POPUP_META['snp_ml_mc_list'][0];
            if (!$ml_mc_list) {
                $ml_mc_list = snp_get_option('ml_mc_list');
            }
            if (snp_get_option('ml_mc_apikey') && $ml_mc_list) {
                $api = new Mailchimp(snp_get_option('ml_mc_apikey'));
                $args = array();
                if (!empty($_POST['name'])) {
                    $args = array('FNAME' => $names['first'], 'LNAME' => $names['last']);
                }
                if (count($cf_data) > 0) {
                    $args = array_merge($args, (array) $cf_data);
                }
                try {
                    $double_optin = snp_get_option('ml_mc_double_optin');
                    if ($double_optin == 1) {
                        $double_optin = true;
                    } else {
                        $double_optin = false;
                    }
                    $double_optin = snp_get_option('ml_mc_double_optin');
                    if ($double_optin == 1) {
                        $double_optin = true;
                    } else {
                        $double_optin = false;
                    }
                    $send_welcome = snp_get_option('ml_mc_send_welcome');
                    if ($send_welcome == 1) {
                        $send_welcome = true;
                    } else {
                        $send_welcome = false;
                    }
                    $retval = $api->lists->subscribe($ml_mc_list, array('email' => $_POST['email']), $args, 'html', $double_optin, false, true, $send_welcome);
                    $Done = 1;
                } catch (Exception $e) {
                    if ($e->getCode() == 214) {
                        $Done = 1;
                    } else {
                        $api_error_msg = $e->getMessage();
                    }
                }
            }
        } elseif (snp_get_option('ml_manager') == 'egoi') {
            $ml_egoi_apikey = snp_get_option('ml_egoi_apikey');
            $client = new SoapClient('http://api.e-goi.com/v2/soap.php?wsdl');
            try {
                $ml_egoi_list = $POPUP_META['snp_ml_egoi_list'][0];
                if (!$ml_egoi_list) {
                    $ml_egoi_list = snp_get_option('ml_egoi_list');
                }
                $args = array('apikey' => $ml_egoi_apikey, 'listID' => $ml_egoi_list, 'email' => $_POST['email']);
                if (!empty($_POST['name'])) {
                    $args['first_name'] = $names['first'];
                    $args['last_name'] = $names['last'];
                }
                if (count($cf_data) > 0) {
                    $CustomFields = array();
                    foreach ($cf_data as $k => $v) {
                        $args[$k] = $v;
                    }
                }
                $res = $client->addSubscriber($args);
                if (isset($res['UID'])) {
                    $Done = 1;
                }
            } catch (Exception $e) {
                // Error...
                // We'll send this by email.
            }
        } elseif (snp_get_option('ml_manager') == 'getresponse') {
            $ml_gr_apikey = snp_get_option('ml_gr_apikey');
            require_once SNP_DIR_PATH . '/include/getresponse/jsonRPCClient.php';
            $api = new jsonRPCClient('http://api2.getresponse.com');
            try {
                $ml_gr_list = $POPUP_META['snp_ml_gr_list'][0];
                if (!$ml_gr_list) {
                    $ml_gr_list = snp_get_option('ml_gr_list');
                }
                $args = array('campaign' => $ml_gr_list, 'email' => $_POST['email']);
                if (!empty($_POST['name'])) {
                    $args['name'] = $_POST['name'];
                }
                if (count($cf_data) > 0) {
                    $CustomFields = array();
                    foreach ($cf_data as $k => $v) {
                        $CustomFields[] = array('name' => $k, 'content' => $v);
                    }
                    $args['customs'] = $CustomFields;
                }
                $res = $api->add_contact($ml_gr_apikey, $args);
                $Done = 1;
            } catch (Exception $e) {
                // Error...
                // We'll send this by email.
                $api_error_msg = $e->getMessage();
            }
        } elseif (snp_get_option('ml_manager') == 'campaignmonitor') {
            require_once SNP_DIR_PATH . '/include/campaignmonitor/csrest_subscribers.php';
            $ml_cm_list = $POPUP_META['snp_ml_cm_list'][0];
            if (!$ml_cm_list) {
                $ml_cm_list = snp_get_option('ml_cm_list');
            }
            $wrap = new CS_REST_Subscribers($ml_cm_list, snp_get_option('ml_cm_apikey'));
            $args = array('EmailAddress' => $_POST['email'], 'Resubscribe' => true);
            if (!empty($_POST['name'])) {
                $args['Name'] = $_POST['name'];
            }
            if (count($cf_data) > 0) {
                $CustomFields = array();
                foreach ($cf_data as $k => $v) {
                    $CustomFields[] = array('Key' => $k, 'Value' => $v);
                }
                $args['CustomFields'] = $CustomFields;
            }
            $res = $wrap->add($args);
            if ($res->was_successful()) {
                $Done = 1;
            } else {
                // Error...
                // We'll send this by email.
                $api_error_msg = 'Failed with code ' . $res->http_status_code;
            }
        } elseif (snp_get_option('ml_manager') == 'icontact') {
            require_once SNP_DIR_PATH . '/include/icontact/iContactApi.php';
            iContactApi::getInstance()->setConfig(array('appId' => snp_get_option('ml_ic_addid'), 'apiPassword' => snp_get_option('ml_ic_apppass'), 'apiUsername' => snp_get_option('ml_ic_username')));
            $oiContact = iContactApi::getInstance();
            $res1 = $oiContact->addContact($_POST['email'], null, null, isset($names['first']) ? $names['first'] : '', isset($names['last']) ? $names['last'] : '', null, null, null, null, null, null, null, null, null);
            if ($res1->contactId) {
                $ml_ic_list = $POPUP_META['snp_ml_ic_list'][0];
                if (!$ml_ic_list) {
                    $ml_ic_list = snp_get_option('ml_ic_list');
                }
                if ($oiContact->subscribeContactToList($res1->contactId, $ml_ic_list, 'normal')) {
                    $Done = 1;
                }
            } else {
                // Error...
                // We'll send this by email.
                $api_error_msg = 'iContact Problem!';
            }
        } elseif (snp_get_option('ml_manager') == 'constantcontact') {
            require_once SNP_DIR_PATH . '/include/constantcontact/class.cc.php';
            $cc = new cc(snp_get_option('ml_cc_username'), snp_get_option('ml_cc_pass'));
            $send_welcome = snp_get_option('ml_cc_send_welcome');
            if ($send_welcome == 1) {
                $cc->set_action_type('contact');
            }
            $email = $_POST['email'];
            $contact_list = $POPUP_META['snp_ml_cc_list'][0];
            if (!$contact_list) {
                $contact_list = snp_get_option('ml_cc_list');
            }
            $extra_fields = array();
            if (!empty($names['first'])) {
                $extra_fields['FirstName'] = $names['first'];
            }
            if (!empty($names['last'])) {
                $extra_fields['LastName'] = $names['last'];
            }
            if (count($cf_data) > 0) {
                $extra_fields = array_merge($extra_fields, (array) $cf_data);
            }
            $contact = $cc->query_contacts($email);
            if ($contact) {
                $status = $cc->update_contact($contact['id'], $email, $contact_list, $extra_fields);
                if ($status) {
                    $Done = 1;
                } else {
                    $api_error_msg = "Contact Operation failed: " . $cc->http_get_response_code_error($cc->http_response_code);
                }
            } else {
                $new_id = $cc->create_contact($email, $contact_list, $extra_fields);
                if ($new_id) {
                    $Done = 1;
                } else {
                    $api_error_msg = "Contact Operation failed: " . $cc->http_get_response_code_error($cc->http_response_code);
                }
            }
        } elseif (snp_get_option('ml_manager') == 'madmimi') {
            require_once SNP_DIR_PATH . '/include/madmimi/MadMimi.class.php';
            if (snp_get_option('ml_madm_username') && snp_get_option('ml_madm_apikey')) {
                $mailer = new MadMimi(snp_get_option('ml_madm_username'), snp_get_option('ml_madm_apikey'));
                $user = array('email' => $_POST['email']);
                if (!empty($names['first'])) {
                    $user['FirstName'] = $names['first'];
                }
                if (!empty($names['last'])) {
                    $user['LastName'] = $names['last'];
                }
                if (count($cf_data) > 0) {
                    $user = array_merge($user, (array) $cf_data);
                }
                $ml_madm_list = $POPUP_META['snp_ml_madm_list'][0];
                if (!$ml_madm_list) {
                    $ml_madm_list = snp_get_option('ml_madm_list');
                }
                $user['add_list'] = $ml_madm_list;
                $res = $mailer->AddUser($user);
                $Done = 1;
            }
        } elseif (snp_get_option('ml_manager') == 'infusionsoft') {
            require_once SNP_DIR_PATH . '/include/infusionsoft/infusionsoft.php';
            if (snp_get_option('ml_inf_subdomain') && snp_get_option('ml_inf_apikey')) {
                $infusionsoft = new Infusionsoft(snp_get_option('ml_inf_subdomain'), snp_get_option('ml_inf_apikey'));
                $user = array('Email' => $_POST['email']);
                if (!empty($names['first'])) {
                    $user['FirstName'] = $names['first'];
                }
                if (!empty($names['last'])) {
                    $user['LastName'] = $names['last'];
                }
                if (count($cf_data) > 0) {
                    $user = array_merge($user, (array) $cf_data);
                }
                $ml_inf_list = $POPUP_META['snp_ml_inf_list'][0];
                if (!$ml_inf_list) {
                    $ml_inf_list = snp_get_option('ml_inf_list');
                }
                $contact_id = $infusionsoft->contact('add', $user);
                $r = $infusionsoft->APIEmail('optIn', $_POST['email'], "Ninja Popups on " . get_bloginfo());
                if ($contact_id && $ml_inf_list) {
                    $infusionsoft->contact('addToGroup', $contact_id, $ml_inf_list);
                }
                if ($contact_id) {
                    $Done = 1;
                }
            }
        } elseif (snp_get_option('ml_manager') == 'aweber') {
            require_once SNP_DIR_PATH . '/include/aweber/aweber_api.php';
            if (get_option('snp_ml_aw_auth_info')) {
                $aw = get_option('snp_ml_aw_auth_info');
                try {
                    $aweber = new AWeberAPI($aw['consumer_key'], $aw['consumer_secret']);
                    $account = $aweber->getAccount($aw['access_key'], $aw['access_secret']);
                    $aw_list = $POPUP_META['snp_ml_aw_lists'][0];
                    if (!$aw_list) {
                        $aw_list = snp_get_option('ml_aw_lists');
                    }
                    $list = $account->loadFromUrl('/accounts/' . $account->id . '/lists/' . $aw_list);
                    $subscriber = array('email' => $_POST['email'], 'ip' => $_SERVER['REMOTE_ADDR']);
                    if (!empty($_POST['name'])) {
                        $subscriber['name'] = $_POST['name'];
                    }
                    if (count($cf_data) > 0) {
                        $subscriber['custom_fields'] = $cf_data;
                    }
                    $r = $list->subscribers->create($subscriber);
                    $Done = 1;
                } catch (AWeberException $e) {
                    $api_error_msg = $e->getMessage();
                }
            }
        } elseif (snp_get_option('ml_manager') == 'wysija' && class_exists('WYSIJA')) {
            $ml_wy_list = $POPUP_META['snp_ml_wy_list'][0];
            if (!$ml_wy_list) {
                $ml_wy_list = snp_get_option('ml_wy_list');
            }
            $userData = array('email' => $_POST['email'], 'firstname' => $names['first'], 'lastname' => $names['last']);
            $data = array('user' => $userData, 'user_list' => array('list_ids' => array($ml_wy_list)));
            $userHelper =& WYSIJA::get('user', 'helper');
            if ($userHelper->addSubscriber($data)) {
                $Done = 1;
            } else {
                $api_error_msg = 'MailPoet Problem!';
            }
        } elseif (snp_get_option('ml_manager') == 'sendpress') {
            $ml_sp_list = $POPUP_META['snp_ml_sp_list'][0];
            if (!$ml_sp_list) {
                $ml_sp_list = snp_get_option('ml_sp_list');
            }
            try {
                SendPress_Data::subscribe_user($ml_sp_list, $_POST['email'], $names['first'], $names['last'], 2);
                $Done = 1;
            } catch (Exception $e) {
                $api_error_msg = 'SendPress Problem!';
            }
        } elseif (snp_get_option('ml_manager') == 'mymail') {
            $userdata = array('firstname' => $names['first'], 'lastname' => $names['last']);
            $ml_mm_list = $POPUP_META['snp_ml_mm_list'][0];
            if (!$ml_mm_list) {
                $ml_mm_list = snp_get_option('ml_mm_list');
            }
            $lists = array($ml_mm_list);
            if (function_exists('mymail')) {
                $entry = $userdata;
                $entry['email'] = $_POST['email'];
                $double_optin = snp_get_option('ml_mm_double_optin');
                if ($double_optin == 1) {
                    $entry['status'] = 0;
                } else {
                    $entry['status'] = 1;
                }
                if (count($cf_data) > 0) {
                    foreach ($cf_data as $k => $v) {
                        $entry[$k] = $v;
                    }
                }
                $subscriber_id = mymail('subscribers')->add($entry, true);
                if (!is_wp_error($subscriber_id)) {
                    $success = mymail('subscribers')->assign_lists($subscriber_id, $lists, false);
                }
                if ($success) {
                    $Done = 1;
                } else {
                    $api_error_msg = 'MyMail Problem!';
                }
            } else {
                $return = mymail_subscribe($_POST['email'], $userdata, $lists);
                if (!is_wp_error($return)) {
                    $Done = 1;
                } else {
                    $api_error_msg = 'MyMail Problem!';
                }
            }
        } elseif (snp_get_option('ml_manager') == 'csv' && snp_get_option('ml_csv_file') && is_writable(SNP_DIR_PATH . 'csv/')) {
            if (!isset($_POST['name'])) {
                $_POST['name'] = '';
            }
            if (count($cf_data) > 0) {
                $CustomFields = '';
                foreach ($cf_data as $k => $v) {
                    $CustomFields .= $k . ' = ' . $v . ';';
                }
            }
            $data = $_POST['email'] . ";" . $_POST['name'] . ";" . $CustomFields . get_the_title($_POST['popup_ID']) . " (" . $_POST['popup_ID'] . ");" . date('Y-m-d H:i') . ";" . $_SERVER['REMOTE_ADDR'] . ";\n";
            if (file_put_contents(SNP_DIR_PATH . 'csv/' . snp_get_option('ml_csv_file'), $data, FILE_APPEND | LOCK_EX) !== FALSE) {
                $Done = 1;
            } else {
                $api_error_msg = 'CSV Problem!';
            }
        }
        if (snp_get_option('ml_manager') == 'email' || !$Done) {
            $Email = snp_get_option('ml_email');
            if (!$Email) {
                $Email = get_bloginfo('admin_email');
            }
            if (!isset($_POST['name'])) {
                $_POST['name'] = '--';
            }
            $error_mgs = '';
            if ($api_error_msg != '') {
                $error_mgs .= "IMPORTANT! You have received this message because connection to your e-mail marketing software failed. Please check connection setting in the plugin configuration.\n";
                $error_mgs .= $api_error_msg . "\n";
            }
            $cf_msg = '';
            if (count($cf_data) > 0) {
                foreach ($cf_data as $k => $v) {
                    $cf_msg .= $k . ": " . $v . "\n";
                }
            }
            $msg = "New subscription on " . get_bloginfo() . "\n" . $error_mgs . "\n" . "E-mail: " . $_POST['email'] . "\n" . "Name: " . $_POST['name'] . "\n" . $cf_msg . "\n" . "Form: " . get_the_title($_POST['popup_ID']) . " (" . $_POST['popup_ID'] . ")\n" . "\n" . "Date: " . date('Y-m-d H:i') . "\n" . "IP: " . $_SERVER['REMOTE_ADDR'] . "";
            wp_mail($Email, "New subscription on " . get_bloginfo(), $msg);
        }
        $result['Ok'] = true;
    }
    echo json_encode($result);
    die('');
}
 public function comment_post($comment_ID, $comment_approved)
 {
     if (isset($_POST['newsletter_signup']) && in_array($comment_approved . '', mymail_option('register_comment_form_status', array()))) {
         $comment = get_comment($comment_ID);
         if (!$this->get_by_mail($comment->comment_author_email)) {
             $lists = apply_filters('mymail_comment_post_lists', mymail_option('register_comment_form_lists', array()), $comment, $comment_approved);
             $user_data = apply_filters('mymail_comment_post_userdata', array('firstname' => $comment->comment_author), $comment, $comment_approved);
             mymail_subscribe($comment->comment_author_email, $user_data, $lists);
         }
     }
 }