function save() { $post_options = array('list', 'email', 'firstname', 'lastname', 'status'); $user_info = array(); foreach ($post_options as $opt) { $user_info[$opt] = isset($_POST['sp_' . $opt]) ? $_POST['sp_' . $opt] : false; } $valid_user = array(); //foreach() if (isset($user_info['list'])) { if (!is_array($user_info['list'])) { $user_info['list'] = array($user_info['list']); } if (isset($user_info['status'])) { $valid_user['status'] = $user_info['status']; } else { $valid_user['status'] = 2; } $data_error = false; if (isset($user_info['email']) && is_email($user_info['email'])) { $valid_user['email'] = $user_info['email']; } else { $data_error = __('Invalid Email', 'sendpress'); } if (isset($user_info['firstname'])) { $valid_user['firstname'] = $user_info['firstname']; } else { $valid_user['firstname'] = ''; } if (isset($user_info['lastname'])) { $valid_user['lastname'] = $user_info['lastname']; } else { $valid_user['lastname'] = ''; } $status = false; if ($data_error == false) { $list = implode(",", $user_info['list']); $custom = apply_filters('sendpress_subscribe_to_list_custom_fields', array(), $_POST); $status = SendPress_Data::subscribe_user($list, $valid_user['email'], $valid_user['firstname'], $valid_user['lastname'], $valid_user['status'], $custom); if ($status == false) { $data_error = __('Problem with subscribing user.', 'sendpress'); } else { $data_error = __('Thanks for subscribing.', 'sendpress'); } } } $this->message = $data_error; }
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(''); }
function html() { if (isset($_POST['sp-shortcode']) && strpos($_POST['sp-shortcode'], 'SC-') !== false) { $cls = str_replace('-', '_', trim($_POST['sp-shortcode'])); call_user_func(array('SendPress_' . $cls, "form_post"), ''); } else { $post_options = array('list', 'email', 'firstname', 'lastname', 'return', 'status'); $user_info = array(); foreach ($post_options as $opt) { $user_info[$opt] = isset($_POST['sp_' . $opt]) ? $_POST['sp_' . $opt] : false; } $valid_user = array(); //foreach() if (isset($user_info['list'])) { if (!is_array($user_info['list'])) { $user_info['list'] = array($user_info['list']); } $data_error = false; if ($user_info['status'] !== false) { $valid_user['status'] = $user_info['status']; } else { $valid_user['status'] = 2; } if ($user_info['email'] !== false && is_email($user_info['email'])) { $valid_user['email'] = $user_info['email']; } else { $data_error = __('Invalid Email', 'sendpress'); } if ($user_info['firstname'] !== false) { $valid_user['firstname'] = $user_info['firstname']; } else { $valid_user['firstname'] = ''; } if ($user_info['lastname'] !== false) { $valid_user['lastname'] = $user_info['lastname']; } else { $valid_user['lastname'] = ''; } $status = false; if ($data_error == false) { $list = implode(",", $user_info['list']); $custom = apply_filters('sendpress_subscribe_to_list_custom_fields', array(), $_POST); $status = SendPress_Data::subscribe_user($list, $valid_user['email'], $valid_user['firstname'], $valid_user['lastname'], $valid_user['status'], $custom); if ($status == false) { $data_error = __('Problem with subscribing user.', 'sendpress'); } } $post_responce = get_post_meta($user_info['list'][0], 'post-page', true); if ($post_responce == false) { $post_responce = 'default'; } if ($user_info['return'] != false) { $post_responce = $user_info['return']; } $optin = SendPress_Option::is_double_optin(); if (isset($_POST['redirect']) && $_POST['redirect'] > 0) { $plink = get_permalink($_POST['redirect']); if ($plink != "") { wp_redirect(esc_url_raw($plink)); exit; } } switch ($post_responce) { case "json": //Respond to post with json data if ($status == false || $data_error != false) { // { success: true/false, list: listid , name: listname, optin: true/false } $info = array("success" => false, "error" => $data_error, "list" => $user_info['list']); } if ($status) { $info = array("success" => true, "error" => $data_error, "list" => $user_info['list'], "optin" => $optin, "email" => $valid_user['email']); } $encoded = json_encode($info); header('Content-type: application/json'); exit($encoded); break; case "custom": $post_redirect = get_post_meta($user_info['list'][0], 'post-page-id', true); if ($post_redirect == false) { $post_redirect = site_url(); } else { $plink = get_permalink($post_redirect); if ($plink != "") { wp_safe_redirect(esc_url_raw($plink)); exit; } } wp_redirect(esc_url_raw($post_redirect)); exit; break; case "redirect": $post_redirect = get_post_meta($user_info['list'][0], 'post-redirect', true); if ($post_redirect == false) { $post_redirect = site_url(); } wp_redirect(esc_url_raw($post_redirect)); exit; break; default: $this->default_page($status, $data_error); } } else { SendPress_Public_View::page_start(); ?> <div class="span12"> <div class='area'> <h1><?php _e('You must provide a list ID for the post page to work', 'sendpress'); ?> .</h1> </div> </div> <?php SendPress_Public_View::page_end(); } } //print_r($email); //echo "Nice Post"; /* $sp->track_click( $info->id , $info->report, $info->urlID , $ip ); $link = get_query_var('spurl'); if( get_query_var('fxti') && get_query_var('spreport') ){ $this->register_click(get_query_var('fxti'), get_query_var('spreport'), $link); } header( 'Location: '.$link ) ; */ }
function subscribe_to_list() { global $wpdb; // Create the response array $response = array('success' => false); if ($_POST) { // get the credit card details submitted by the form $first = isset($_POST['first']) ? $_POST['first'] : ''; $last = isset($_POST['last']) ? $_POST['last'] : ''; $email = isset($_POST['email']) ? $_POST['email'] : ''; $listid = isset($_POST['listid']) ? $_POST['listid'] : ''; $custom = apply_filters('sendpress_subscribe_to_list_custom_fields', array(), $_POST); $success = SendPress_Data::subscribe_user($listid, $email, $first, $last, 2, $custom); if (false !== $success) { $response['success'] = true; $response['exists'] = $success['already']; } else { $response['error'] = __('User was not subscribed to the list.', 'sendpress'); } } // Add additional processing here if ($response['success']) { // Succeess } else { // Failed } // Serialize the response back as JSON echo json_encode($response); die; }
header('HTTP/1.0 403 Forbidden'); die; } /** * * SENDPRESS FRONT END ACTIONS * * see @sendpress class line 101 * Handles saving data and other user actions. * **/ global $sendpress_show_thanks, $sendpress_signup_error; switch ($this->_current_action) { case 'signup-user': $sendpress_show_thanks = false; $sendpress_signup_error = "There was an error signing up, please try again."; $s = new SendPress(); $first = isset($_POST['first']) ? $_POST['first'] : ''; $last = isset($_POST['last']) ? $_POST['last'] : ''; $email = isset($_POST['email']) ? $_POST['email'] : ''; $listid = isset($_POST['list']) ? $_POST['list'] : ''; $custom = apply_filters('sendpress_subscribe_to_list_custom_fields', array(), $_POST); $success = SendPress_Data::subscribe_user($listid, $email, $first, $last, 2, $custom); //need to do stuff with the form on the page //var_dump($success); if ((bool) $success) { $sendpress_signup_error = ""; $sendpress_show_thanks = true; } break; }
function subscribe_user($listid, $email, $first, $last) { _deprecated_function(__FUNCTION__, '0.8.9', 'SendPress_Data::subscribe_user()'); SendPress_Data::subscribe_user($listid, $email, $first, $last); }