public function handle_submission() { $double_opt_in = mymail_option('double_opt_in'); $baselink = get_permalink(mymail_option('homepage')); if (!$baselink) { $baselink = site_url(); } $referer = isset($_POST['_referer']) ? $_POST['_referer'] : $baselink; $forms = mymail_option('forms'); $form_id = isset($forms[$_POST['formid']]) ? intval($_POST['formid']) : 0; $form = $forms[$form_id]; $userdata = array(); $customfields = mymail_option('custom_field'); foreach ($form['order'] as $field) { $userdata[$field] = isset($_POST['userdata'][$field]) ? esc_attr($_POST['userdata'][$field]) : ''; if ($field == 'email' && !mymail_is_email(trim($userdata[$field])) || !$userdata[$field] && in_array($field, $form['required'])) { $this->errors[$field] = mymail_text($field, isset($customfields[$field]['name']) ? $customfields[$field]['name'] : $field); } } $userdata['email'] = trim($userdata['email']); $this->values = $userdata; if (mymail_option('track_users')) { $userdata['_meta'] = array('ip' => mymail_get_ip(), 'signupip' => mymail_get_ip(), 'signuptime' => current_time('timestamp')); } $this->lists = isset($form['userschoice']) ? isset($_POST['lists']) ? (array) $_POST['lists'] : array() : $form['lists']; $this->errors = apply_filters('mymail_submit_errors', $this->errors); $this->lists = apply_filters('mymail_submit_lists', $this->lists); $userdata = apply_filters('mymail_submit_userdata', $userdata); if (empty($this->lists)) { $this->errors['lists'] = __('Select at least one list', 'mymail'); } if ($this->valid()) { $email = $userdata['email']; if ($double_opt_in) { //send confirmation email global $mymail_subscriber; if ($e = $mymail_subscriber->send_confirmation($baselink, $email, $userdata, $this->lists, false, isset($form['template']) ? $form['template'] : 'notification.html')) { $target = add_query_arg(array('confirm' => ''), $baselink); } else { //error } } else { global $mymail_subscriber; unset($userdata['email']); //subscribe user if ($mymail_subscriber->insert($email, 'subscribed', $userdata, $this->lists)) { $target = add_query_arg(array('subscribe' => ''), $baselink); } else { //error } } //redirect if no ajax request oder extern if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || isset($_POST['_extern'])) { $target = !empty($form['redirect']) ? $form['redirect'] : add_query_arg(array('mymail_success' => $double_opt_in + 1, 'id' => $form_id, 'extern' => isset($_POST['_extern'])), $referer); wp_redirect(apply_filters('mymail_subscribe_target', $target, $form_id)); } else { $return = array('html' => '<p>' . ($double_opt_in ? mymail_text('confirmation') : mymail_text('success')) . '</p>'); if (!empty($form['redirect'])) { $return = wp_parse_args(array('redirect' => $form['redirect']), $return); } return $return; } return $target; } else { //redirect if no ajax request oder extern if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || isset($_POST['_extern'])) { $save = array('values' => $this->values, 'errors' => $this->errors, 'lists' => $this->lists); $hash = md5(serialize($save)); set_transient('mymail_error_' . $hash, $save); $target = add_query_arg(array('mymail_error' => $hash, 'id' => $form_id, 'extern' => isset($_POST['_extern'])), $referer); wp_redirect($target); } return array('error' => true, 'fields' => $this->errors, 'html' => $this->get_error_html()); } }
public function columns_content($column) { global $post; global $wpdb; if ($post->post_status != 'autoresponder') { return $column; } $campaign = get_post_meta($post->ID, 'mymail-campaign', true); $data = get_post_meta($post->ID, 'mymail-data', true); $specialcamp = !in_array($data['autoresponder']['action'], array('mymail_subscriber_insert', 'mymail_subscriber_unsubscribed')); switch ($column) { case "status": $active = isset($data['active_autoresponder']) && $data['active_autoresponder'] ? 'active' : 'inactive'; $is_active = $active == 'active'; include MYMAIL_DIR . '/includes/autoresponder.php'; echo '<span class="mymail-icon ' . $active . '"></span> ' . ($is_active ? __('active', 'mymail') : __('inactive', 'mymail')) . '<br>'; echo '<span class="autoresponder-' . $active . '">'; $autoresponder = $data['autoresponder']; echo sprintf(__('send %1$s %2$s %3$s', 'mymail'), $autoresponder['amount'] ? '<strong>' . $autoresponder['amount'] . '</strong> ' . $mymail_autoresponder_info['units'][$autoresponder['unit']] : __('immediately', 'mymail'), __('after', 'mymail'), ' <strong>' . $mymail_autoresponder_info['actions'][$autoresponder['action']]['label'] . '</strong>'); $lists = wp_get_post_terms($post->ID, 'newsletter_lists', array("fields" => "names")); echo !empty($lists) ? '<br>' . (!$specialcamp ? __('in one of these lists', 'mymail') : __('Lists', 'mymail')) . ':<br><strong>' . implode('</strong>, <strong>', $lists) . '</strong>' : '<br><span class="mymail-icon warning"></span> ' . __('no lists selected', 'mymail'); if (isset($autoresponder['advanced'])) { $fields = apply_filters('mymail_autoresponder_condition_fields', array('email' => mymail_text('email'), 'firstname' => mymail_text('firstname'), 'lastname' => mymail_text('lastname'))); echo '<br>' . __('only if', 'mymail') . '<br>'; $conditions = array(); foreach ($autoresponder['conditions'] as $condition) { if (!isset($fields[$condition['field']])) { echo '<span class="mymail-icon warning"></span> ' . sprintf(__('%s is missing!', 'mymail'), '"' . $condition['field'] . '"') . '<br>'; continue; } $conditions[] = '<strong>' . $fields[$condition['field']] . '</strong> ' . $mymail_autoresponder_info['operators'][$condition['operator']] . ' "<strong>' . $condition['value'] . '</strong>"'; } echo implode('<br>' . __(strtolower($autoresponder['operator']), 'mymail') . ' ', $conditions); } echo '</span>'; if (current_user_can('mymail_edit_autoresponders') && (get_current_user_id() == $post->post_author || current_user_can('mymail_edit_others_autoresponders'))) { $jobs = $this->get_job_count($post->ID); echo '<div class="row-actions">'; $actions = array(); if ($active != 'active') { $actions['activate'] = '<a class="start" href="?post_type=newsletter&activate=' . $post->ID . (isset($_REQUEST['post_status']) ? '&post_status=' . $_REQUEST['post_status'] : '') . '&_wpnonce=' . wp_create_nonce('mymail_nonce') . '" title="' . __('activate', 'mymail') . '">' . __('activate', 'mymail') . '</a> '; } else { $actions['deactivate'] = '<a class="start" href="?post_type=newsletter&deactivate=' . $post->ID . (isset($_REQUEST['post_status']) ? '&post_status=' . $_REQUEST['post_status'] : '') . '&_wpnonce=' . wp_create_nonce('mymail_nonce') . '" title="' . __('deactivate', 'mymail') . '">' . __('deactivate', 'mymail') . '</a> '; } if ($jobs) { $actions['flushjobs'] = '<a class="start" onclick="return confirm(\'' . esc_html(__('You are about to delete all upcoming jobs for this auto responder.', 'mymail')) . '\');" href="?post_type=newsletter&flushjobs=' . $post->ID . (isset($_REQUEST['post_status']) ? '&post_status=' . $_REQUEST['post_status'] : '') . '&_wpnonce=' . wp_create_nonce('mymail_nonce') . '" title="' . __('remove all future jobs', 'mymail') . '">' . sprintf(_n('remove %d upcoming job', 'remove %d upcoming jobs', $jobs, 'mymail'), $jobs) . '</a> '; } echo implode(' | ', $actions); echo '</div>'; } break; case "total": echo !empty($campaign) && !$specialcamp ? number_format_i18n($campaign['sent']) : '–'; if (!empty($campaign['errors'])) { echo ' <a href="edit.php?post_status=error&post_type=subscriber" class="errors" title="' . sprintf(__('%d emails have not been sent', 'mymail'), count($campaign['errors'])) . '">(+' . count($campaign['errors']) . ')</a>'; } break; case "open": if (isset($campaign['opens']) && !$specialcamp) { $opens = $campaign['opens']; echo number_format_i18n($opens) . '/<span class="tiny">' . number_format_i18n($campaign['sent']) . '</span>'; echo "<br><span title='" . __('open rate', 'mymail') . "' class='nonessential' style='padding:0;'>"; echo $opens ? ' (' . round($opens / $campaign['sent'] * 100, 2) . '%)' : ' (0%)'; echo "</span>"; } else { echo '–'; } break; case "click": if (isset($campaign['totaluniqueclicks']) && !$specialcamp) { $clicks = $campaign['totaluniqueclicks']; echo number_format_i18n($clicks); echo "<br><span title='" . __('click rate', 'mymail') . "' class='nonessential' style='padding:0;'>"; echo $clicks ? ' (' . round($campaign['totaluniqueclicks'] / $campaign['opens'] * 100, 2) . '%)' : ' (0%)'; echo "</span>"; } else { echo '–'; } break; case "unsubs": if (isset($campaign['unsubscribes']) && !$specialcamp) { echo number_format_i18n($campaign['unsubscribes']); echo "<br><span title='" . __('unsubscribe rate', 'mymail') . "' class='nonessential' style='padding:0;'>"; echo $campaign['unsubscribes'] ? ' (' . round($campaign['unsubscribes'] / $campaign['opens'] * 100, 2) . '%)' : ' (0%)'; echo "</span>"; } else { echo '–'; } break; case "bounces": if (isset($campaign['hardbounces']) && !$specialcamp) { echo number_format_i18n($campaign['hardbounces']); echo "<br><span title='" . __('bounce rate', 'mymail') . "' class='nonessential' style='padding:0;'>"; echo $campaign['hardbounces'] ? ' (' . round($campaign['hardbounces'] / ($campaign['sent'] + $campaign['hardbounces']) * 100, 2) . '%)' : ' (0%)'; echo "</span>"; } else { echo '–'; } break; } }
public function ajax_do_export() { $return['success'] = false; $this->ajax_nonce(json_encode($return)); if (!current_user_can('mymail_export_subscribers')) { $return['msg'] = 'no allowed'; echo json_encode($return); exit; } $filename = get_transient('mymail_export_filename'); if (!file_exists($filename) || !is_writeable($filename)) { $return['msg'] = 'error'; echo json_encode($return); exit; } parse_str($_POST['data'], $d); $offset = intval($_POST['offset']); $limit = intval($_POST['limit']); $raw_data = array(); $encoding = $d['encoding']; $outputformat = $d['outputformat']; $useheader = $offset === 0 && isset($d['header']); if ($useheader) { $row = array(); $customfields = mymail_option('custom_field', array()); foreach ($d['column'] as $col) { switch ($col) { case '_number': $val = '#'; break; case 'email': case 'firstname': case 'lastname': $val = mymail_text($col, $col); break; case '_listnames': $val = __('Lists', 'mymail'); break; case '_status': $val = __('Status', 'mymail'); break; case '_ip': $val = __('IP Address', 'mymail'); break; case '_signuptime': $val = __('Signup Date', 'mymail'); break; case '_signupip': $val = __('Signup IP', 'mymail'); break; case '_confirmtime': $val = __('Confirm Date', 'mymail'); break; case '_confirmip': $val = __('Confirm IP', 'mymail'); break; default: $val = isset($customfields[$col]) ? $customfields[$col]['name'] : ''; } $val = mb_convert_encoding($val, $encoding, 'UTF-8'); $row[] = str_replace(';', ',', $val); } $raw_data[] = $row; } $offset = $offset * $limit; global $wpdb; if (isset($d['nolists'])) { $sql = "SELECT ID, post_title a FROM {$wpdb->posts} a LEFT JOIN {$wpdb->users} u ON (a.post_author = u.ID) WHERE a.post_status IN ('" . implode("','", $d['status']) . "') AND a.post_type IN('subscriber') AND a.ID NOT IN (SELECT object_id FROM {$wpdb->term_relationships} tr LEFT JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE taxonomy = 'newsletter_lists')"; $data = $wpdb->get_results($sql); } if (!empty($d['lists'])) { $sql = "SELECT ID, post_title, post_status FROM {$wpdb->posts} a LEFT JOIN {$wpdb->term_relationships} b ON ( a.ID = b.object_id ) LEFT JOIN {$wpdb->postmeta} c ON ( a.ID = c.post_id ) LEFT JOIN {$wpdb->term_taxonomy} d ON ( d.term_taxonomy_id = b.term_taxonomy_id ) LEFT JOIN {$wpdb->terms} e ON ( e.term_id = d.term_id ) WHERE a.post_type IN('subscriber') AND a.post_status IN ('" . implode("','", $d['status']) . "') AND e.term_id IN (" . implode(',', $d['lists']) . ") GROUP BY a.ID LIMIT {$offset}, {$limit};"; $data = $wpdb->get_results($sql); $counter = 1 + $offset; foreach ($data as $user) { $userdata = get_post_meta($user->ID, 'mymail-userdata', true); $row = array(); foreach ($d['column'] as $col) { switch ($col) { case '_number': $val = $counter; break; case 'email': $val = $user->post_title; break; case '_listnames': $terms = wp_get_post_terms($user->ID, 'newsletter_lists', array("fields" => "names")); $val = implode(', ', $terms); break; case '_status': $val = __($user->post_status, 'mymail'); break; case '_ip': $val = isset($userdata['_meta']['ip']) ? $userdata['_meta']['ip'] : ''; break; case '_signuptime': $val = isset($userdata['_meta']['signuptime']) ? $d['dateformat'] ? date($d['dateformat'], $userdata['_meta']['signuptime']) : $userdata['_meta']['signuptime'] : ''; break; case '_signupip': $val = isset($userdata['_meta']['signupip']) ? $userdata['_meta']['signupip'] : ''; break; case '_confirmtime': $val = isset($userdata['_meta']['confirmtime']) ? $d['dateformat'] ? date($d['dateformat'], $userdata['_meta']['confirmtime']) : $userdata['_meta']['confirmtime'] : ''; break; case '_confirmip': $val = isset($userdata['_meta']['confirmip']) ? $userdata['_meta']['confirmip'] : ''; break; default: $val = isset($userdata[$col]) ? apply_filters('mymail_export_custom_field', $userdata[$col], $col) : ''; } $val = mb_convert_encoding($val, $encoding, 'UTF-8'); $row[] = str_replace(';', ',', $val); } $raw_data[] = $row; $counter++; } $output = ''; if ($outputformat == 'html') { if ($useheader) { $firstrow = array_shift($raw_data); $output .= '<tr><th>' . implode('</th><th>', $firstrow) . "</th></tr>\n"; } foreach ($raw_data as $row) { $output .= '<tr><td>' . implode('</td><td>', $row) . "</td></tr>\n"; } } else { foreach ($raw_data as $row) { $output .= implode(';', $row) . "\n"; } } try { $bytes = file_put_contents($filename, $output, FILE_APPEND); $return['total'] = size_format(filesize($filename), 2); $return['success'] = true; if ($bytes === 0) { $return['finished'] = true; mymail_require_filesystem(); global $wp_filesystem; //finished $folder = MYMAIL_UPLOAD_DIR; $finalname = dirname($filename) . '/mymail_export_' . date('Y-m-d-H-i-s') . '.' . $outputformat; $return['success'] = copy($filename, $finalname); $wp_filesystem->delete($filename); $return['filename'] = admin_url('admin-ajax.php?action=mymail_download_export_file&file=' . basename($finalname) . '&format=' . $outputformat . '&_wpnonce=' . wp_create_nonce('mymail_nonce')); } } catch (Exception $e) { $return['success'] = false; $return['msg'] = $e->getMessage(); } } echo json_encode($return); exit; }
:</label> <input type="text" name="mymail_options[text][unsubscribelink]" value="<?php echo esc_attr(mymail_text('unsubscribelink')); ?> " class="regular-text"></div> <div class="mymail_text"><label><?php _e('Webversion Link', 'mymail'); ?> :</label> <input type="text" name="mymail_options[text][webversion]" value="<?php echo esc_attr(mymail_text('webversion')); ?> " class="regular-text"></div> <div class="mymail_text"><label><?php _e('Forward Link', 'mymail'); ?> :</label> <input type="text" name="mymail_options[text][forward]" value="<?php echo esc_attr(mymail_text('forward')); ?> " class="regular-text"></div> </td> </tr> </table> </div> <div id="tab-tags" class="tab"> <table class="form-table"> <tr valign="top"> <td class="tags" colspan="2"> <p class="description"><?php echo sprintf(__('Tags are placeholder for your newsletter. You can set them anywhere in your newsletter template with the format %s. Custom field tags are induvidual for each subscriber.', 'mymail'), '<code>{tagname}</code>'); ?> </p>
echo mymail_text('firstname', __('First Name', 'mymail')); ?> </label> <code title="<?php echo sprintf(__('use %1$s as placeholder tag to replace it with %2$s', 'mymail'), '{fullname}', '"' . trim($this->user_data['firstname'] . ' ' . $this->user_data['lastname']) . '"'); ?> ">{fullname}</code> <code title="<?php echo sprintf(__('use %1$s as placeholder tag to replace it with %2$s'), '{firstname}', '"' . $this->user_data['firstname'] . '"'); ?> ">{firstname}</code><br><input type="text" id="mymail_data_firstname" name="mymail_data[firstname]" tabindex="1" value="<?php echo $this->user_data['firstname']; ?> " class="regular-text input"> </div> <div> <label for="mymail_data_lastname"><?php echo mymail_text('lastname', __('Last Name', 'mymail')); ?> </label> <code title="<?php echo sprintf(__('use %1$s as placeholder tag to replace it with %2$s', 'mymail'), '{lastname}', '"' . $this->user_data['lastname'] . '"'); ?> ">{lastname}</code><br><input type="text" id="mymail_data_lastname" name="mymail_data[lastname]" tabindex="1" value="<?php echo $this->user_data['lastname']; ?> " class="regular-text input"> </div> <?php if ($customfield = mymail_option('custom_field')) { foreach ($customfield as $field => $data) { ?> <div class="custom-field-wrap"> <?php
public function cronjob($cron_used = false) { if (defined('DOING_AJAX') || defined('DOING_AUTOSAVE') || defined('WP_INSTALLING')) { return false; } //define a constant with the time so we can take a look define('MYMAIL_DOING_CRON', time()); if (!$cron_used) { if (mymail_option('cron_service') != 'wp_cron') { $this->remove_crons(); return false; } else { sleep(2); } } $safe_mode = @ini_get('safe_mode'); $memory_limit = @ini_get('memory_limit'); $max_execution_time = @ini_get('max_execution_time'); //lockfile exists if (file_exists(MYMAIL_UPLOAD_DIR . '/CRON_LOCK')) { $age = time() - filemtime(MYMAIL_UPLOAD_DIR . '/CRON_LOCK'); if ($age < 10) { echo "Cron is currently running!"; return false; } else { if ($age < ini_get('max_execution_time')) { mymail_notice('<strong>' . sprintf(__('It seems your last cronjob hasn\'t been finished! Increase the %1$s, add %2$s to your wp-config.php or reduce the %3$s in the settings', 'mymail'), "'max_execution_time'", '<code>define("WP_MEMORY_LIMIT", "256M");</code>', '<a href="options-general.php?page=newsletter-settings&settings-updated=true#delivery">' . __('Number of mails sent', 'mymail') . '</a>') . '</strong>', 'error', false, 'cron_unfinished'); die; } else { } } } else { file_put_contents(MYMAIL_UPLOAD_DIR . '/CRON_LOCK', time()); } $this->check_bounces(); if (!$safe_mode) { @set_time_limit(0); if (intval($max_execution_time) < 300) { @ini_set('max_execution_time', 300); $max_execution_time = @ini_get('max_execution_time'); } if (intval($memory_limit) < 256) { @ini_set('memory_limit', '256M'); $memory_limit = @ini_get('memory_limit'); } } @ignore_user_abort(true); register_shutdown_function(array($this, 'finish_cron')); global $wpdb, $mymail_campaignID, $mymail_campaigndata; $query = "SELECT * FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_type = 'newsletter' AND {$wpdb->posts}.post_status IN ('active', 'queued') GROUP BY {$wpdb->posts}.ID ORDER BY {$wpdb->posts}.post_modified ASC"; $campaigns = $wpdb->get_results($query); $campaign_count = count($campaigns); $campaign_active_count = 0; for ($i = 0; $i < $campaign_count; $i++) { if ($campaigns[$i]->post_status == 'active') { $campaign_active_count++; } } $mymail_campaignID = $mymail_campaigndata = array(); $max_memory_usage = 0; //how many newsletter sent at once $send_at_once = mymail_option('send_at_once'); $send_per_camp = $campaign_active_count && mymail_option('split_campaigns') ? ceil($send_at_once / $campaign_active_count) : $send_at_once; $max_bounces = mymail_option('bounce_attempts'); $sent_this_turn = 0; $send_delay = intval(mymail_option('send_delay', 0)) * 1000; $bounces_only = true; $senderrors = array(); $quit_cronjob = !$campaign_count; $unsubscribe_homepage = get_page(mymail_option('homepage')) ? get_permalink(mymail_option('homepage')) : get_bloginfo('url'); $unsubscribe_homepage = apply_filters('mymail_unsubscribe_link', $unsubscribe_homepage); if ($memory_limit) { $this->cron_log('memory limit', '<strong>' . intval($memory_limit) . ' MB</strong>'); } $this->cron_log('safe_mode', '<strong>' . ($safe_mode ? 'enabled' : 'disabled') . '</strong>'); $this->cron_log('max_execution_time', '<strong>' . $max_execution_time . ' seconds</strong>'); $this->cron_log('campaigns found', '<strong>' . $campaign_active_count . '</strong>'); $this->cron_log('send max at once', '<strong>' . $send_at_once . '</strong>'); $this->cron_log(); for ($i = 0; $i < $campaign_count; $i++) { $time_start = microtime(true); $break_on_error = false; //current newsletter $campaign = $campaigns[$i]; $campaign_permalink = get_permalink($campaign->ID); //get data from the newsletter $data = get_post_meta($campaign->ID, 'mymail-data', true); //if mail is less then an hour in the future and if (current_time('timestamp') - $data['timestamp'] > -3600) { $quit_cronjob = false; } ///allready sent, not active or in the future go to next if (current_time('timestamp') - $data['timestamp'] < 0) { continue; } //change post status to active (silence) if ($campaign->post_status == 'queued') { $this->change_status($campaign, 'active', true); } //to many this turn => break; if ($sent_this_turn >= $send_at_once) { break; } //get more data from the newsletter $campaigncount = count($mymail_campaigndata); $mymail_campaignID[] = $campaign->ID; $mymail_campaigndata[$campaigncount] = get_post_meta($campaign->ID, 'mymail-campaign', true); $lists = wp_get_post_terms($campaign->ID, 'newsletter_lists', array("fields" => "ids")); //baselink with trailing slash required for links to work in Outlook 2007 $baselink = add_query_arg('mymail', $campaign->ID, home_url('/')); $unsubscribelink = add_query_arg('unsubscribe', md5($campaign->ID . '_unsubscribe'), $unsubscribe_homepage); $errors = $mymail_campaigndata[$campaigncount]['errors']; $totalerrors = isset($mymail_campaigndata[$campaigncount]['totalerrors']) ? $mymail_campaigndata[$campaigncount]['totalerrors'] : count($mymail_campaigndata[$campaigncount]['errors']); require_once MYMAIL_DIR . '/classes/mail.class.php'; $mail = mymail_mail::get_instance(); //stop if send limit is reached if ($mail->sentlimitreached) { break; } $mail->from = $data['from']; $mail->from_name = $data['from_name']; $mail->bouncemail = mymail_option('bounce'); $mail->reply_to = $data['reply_to']; $mail->embed_images = $data['embed_images']; require_once MYMAIL_DIR . '/classes/placeholder.class.php'; $placeholder = new mymail_placeholder($campaign->post_content); $placeholder->add(array('preheader' => $data['preheader'], 'subject' => $data['subject'], 'webversion' => '<a href="{webversionlink}">' . mymail_text('webversion') . '</a>', 'webversionlink' => $campaign_permalink, 'unsub' => '<a href="{unsublink}">' . mymail_text('unsubscribelink') . '</a>', 'unsublink' => $unsubscribelink, 'forward' => '<a href="{forwardlink}">' . mymail_text('forward') . '</a>', 'email' => '<a href="mailto:{emailaddress}">{emailaddress}</a>')); $placeholder->share_service($campaign_permalink, $campaign->post_title); $mail->content = $placeholder->get_content(false); $mail->baselink = $baselink; $mail->prepare_content(); //store the base content temporary; $basecontent = $mail->content; //get all links from the basecontent preg_match_all('#href=(\'|")?(https?[^\'"\\#]+)(\'|")?#', $basecontent, $links); $links = $links[2]; $totalsend = 0; $term_taxonomy_ids = wp_list_pluck(get_terms('newsletter_lists', array('fields' => 'all', 'include' => $lists)), 'term_taxonomy_id'); //no subscribers if (empty($term_taxonomy_ids) || empty($lists)) { continue; } //get all users from all lists only once ordered by ID $query = "SELECT {$wpdb->posts}.ID, {$wpdb->posts}.post_name AS hash, {$wpdb->posts}.post_title AS email, {$wpdb->posts}.post_status as status, {$wpdb->postmeta}.meta_value as meta FROM {$wpdb->posts} INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) LEFT JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = 'mymail-campaigns') WHERE ( {$wpdb->term_relationships}.term_taxonomy_id IN (" . implode(',', $term_taxonomy_ids) . ") ) AND {$wpdb->posts}.post_type = 'subscriber' AND ({$wpdb->posts}.post_status IN ('subscribed', 'unsubscribed')) GROUP BY {$wpdb->posts}.ID ORDER BY {$wpdb->posts}.ID ASC"; $result = mysql_query($query, $wpdb->dbh); $subscribers_count = mysql_num_rows($result); $this->cron_log('Campaign', '<strong>' . $campaign->post_title . '</strong>'); $this->cron_log('Subscribers found', '<strong>' . $subscribers_count . '</strong>'); $this->cron_log('send max for camp', '<strong>' . $send_per_camp . '</strong>'); $this->cron_log(); if ($error = mysql_error($wpdb->dbh)) { die($error); } $subscribercounter = $totalsend; $campaign_send_counter = 0; //foreach subscribers while ($subscriber = @mysql_fetch_object($result)) { if (!$safe_mode) { @set_time_limit(0); } touch(MYMAIL_UPLOAD_DIR . '/CRON_LOCK'); if (connection_aborted()) { break; } $subscribercounter++; //to many send for this campaign; if ($campaign_send_counter >= $send_per_camp) { break; } if ($break_on_error) { break; } //to many this turn => break; if ($sent_this_turn >= $send_at_once) { break; } //stop if send limit is reached if ($mail->sentlimitreached) { break; } if (!isset($subscriber)) { break; } $usercampaigndata = $subscriber->meta ? unserialize($subscriber->meta) : array(); //check if campaign was sent if ($usercampaigndata[$campaign->ID]['sent'] || $subscribercounter <= 0) { //campaign was sent $totalsend++; continue; } else { //stop if user isn't subscribed if ($subscriber->status != 'subscribed') { continue; } //not sent //user reaches bouncelimit if ($usercampaigndata[$campaign->ID]['bounces'] >= $max_bounces) { continue; } $time_mail_start = microtime(true); $userdata = get_post_meta($subscriber->ID, 'mymail-userdata', true); if (!is_array($userdata)) { $userdata = array(); } $mail->to = $subscriber->email; $mail->hash = $subscriber->hash; $mail->subject = $data['subject']; //restore from the base $placeholder->set_content($basecontent); //unset meta property if set if (isset($userdata['_meta'])) { unset($userdata['_meta']); } $placeholder->add(array_merge(array('fullname' => trim($userdata['firstname'] . ' ' . $userdata['lastname']), 'forwardlink' => add_query_arg('forward', $subscriber->email, $campaign_permalink)), array('emailaddress' => $subscriber->email), $userdata)); //replace links $placeholder->replace_links($baselink, $links, $subscriber->hash); $mail->content = $placeholder->get_content(); //placeholders in subject $placeholder->set_content($data['subject']); $mail->subject = $placeholder->get_content(); //set headers for bouncing $mail->add_header('X-MyMail', $subscriber->hash); $mail->add_header('X-MyMail-Campaign', $campaign->ID); $mail->add_header('List-Unsubscribe', add_query_arg(array('k' => $campaign->ID, 'unsubscribe' => $subscriber->hash), $unsubscribelink)); try { $success = $mail->send(); } catch (Exception $e) { $success = false; } //send mail if ($success) { //mark as send and increase total with 1 $usercampaigndata[$campaign->ID]['sent'] = true; $usercampaigndata[$campaign->ID]['timestamp'] = current_time('timestamp'); $this->post_meta($subscriber->ID, 'mymail-campaigns', $usercampaigndata); if (!isset($usercampaigndata[$campaign->ID]['bounces'])) { $bounces_only = false; } //campaign was sent $totalsend++; $sent_this_turn++; $campaign_send_counter++; $this->cron_log('#' . $subscribercounter . ' <strong>' . $subscriber->email . '</strong> sent', 'try ' . ($usercampaigndata[$campaign->ID]['bounces'] + 1) . '.', microtime(true) - $time_mail_start); } else { $e_array = $mail->get_errors('array'); $errormsg = trim($e_array[count($e_array) - 1]); if (!$errormsg) { if (!$campaign->post_content) { $errormsg = 'no content'; } else { $errormsg = ''; } } $subscriber_errors = apply_filters('mymail_subscriber_errors', array('SMTP Error: The following recipients failed', 'The following From address failed', 'Invalid address:', 'SMTP Error: Data not accepted')); $is_subscriber_error = !mymail_is_email($subscriber->email); //check for subscriber error foreach ($subscriber_errors as $subscriber_error) { if (stripos($errormsg, $subscriber_error) !== false) { $is_subscriber_error = true; break; } } //caused by the subscriber if ($is_subscriber_error) { $this->cron_log('#' . $subscribercounter . ' <strong>' . $subscriber->email . '</strong> <span style="color:#f33">not sent</span>', '<br><span style="color:#f33">' . $errormsg . '</span>', microtime(true) - $time_mail_start); $usercampaigndata[$campaign->ID]['sent'] = false; //change status $this->change_status(get_post($subscriber->ID), 'error'); $errors[$subscriber->email] = $errormsg; $totalerrors++; do_action('mymail_subscriber_error', $campaign, $subscriber, $errormsg); //campaign failure } else { if (!empty($e_array)) { $senderrors[] = $mail->get_errors('br'); $break_on_error = true; } elseif ($errormsg) { $senderrors[] = $errormsg; $break_on_error = true; } if ($break_on_error) { $this->cron_log('Campaign paused cause of a sending error: <span style="color:#f33">' . $errormsg . '</span>'); } } $this->post_meta($subscriber->ID, 'mymail-campaigns', $usercampaigndata); } $max_memory_usage = max($max_memory_usage, memory_get_peak_usage(true)); $took_mail = (microtime(true) - $time_mail_start) * 1000; //pause if ($send_delay) { usleep(max(1, round($send_delay - $took_mail))); } } } $max_memory_usage = max($max_memory_usage, memory_get_peak_usage(true)); mysql_free_result($result); $this->cron_log(); $took = microtime(true) - $time_start; if ($max_memory_usage) { $this->cron_log('max. memory usage', '<strong>' . size_format($max_memory_usage, 2) . '</strong>'); } $this->cron_log('sent this turn', $sent_this_turn); if ($sent_this_turn) { $this->cron_log('time', round($took, 2) . ' sec., (' . round($took / $sent_this_turn, 4) . '/mail)'); } $this->cron_log(); //close connection if smtp $mail->close(); //load it again cause it may changed during sending wp_cache_delete($campaign->ID, 'post' . '_meta'); $mymail_campaigndata[$campaigncount] = get_post_meta($campaign->ID, 'mymail-campaign', true); //count users and save to campaign $mymail_campaigndata[$campaigncount]['sent'] = $totalsend; $mymail_campaigndata[$campaigncount]['errors'] = $errors; $mymail_campaigndata[$campaigncount]['totalerrors'] = $totalerrors; if ($break_on_error) { $this->change_status($campaign, 'paused'); mymail_notice(sprintf(__('Campaign %1$s has been paused cause of a sending error: %2$s', 'mymail'), '<a href="post.php?post=' . $campaign->ID . '&action=edit"><strong>' . $campaign->post_title . '</strong></a>', '<strong>' . implode('', $senderrors)) . '</strong>', 'error', false, 'camp_error_' . $campaign->ID); do_action('mymail_break_on_error', $campaign, $senderrors); //campaign is finished (or no mail was sent cause no subscriber) } else { //recalc totals $mymail_campaigndata[$campaigncount]['total'] = $this->get_totals_by_id($campaign->ID) + $mymail_campaigndata[$campaigncount]['unsubscribes'] + $mymail_campaigndata[$campaigncount]['hardbounces'] - $totalerrors; //stop with no subscribers if ($mymail_campaigndata[$campaigncount]['total'] == 0) { continue; } //recalculate totals if sent is more or equal the once in the database /* if($mymail_campaigndata[$campaigncount]['sent'] >= $subscribers_count){ //$mymail_campaigndata[$campaigncount]['total'] = $this->get_totals_by_id($campaign->ID, true, true)+$mymail_campaigndata[$campaigncount]['unsubscribes']-$totalerrors; } */ //obviously finished if ($mymail_campaigndata[$campaigncount]['sent'] + $mymail_campaigndata[$campaigncount]['hardbounces'] >= $mymail_campaigndata[$campaigncount]['total']) { $mymail_campaigndata[$campaigncount]['timestamp'] = current_time('timestamp'); //change campaign to finished and replace the dyamic content $placeholder->clear_placeholder(); $placeholder->set_content($campaign->post_content); //$placeholder->add($placeholder->get_dynamic()); //remove the KSES filter which strips "unwanted" tags and attributes remove_filter('content_save_pre', 'wp_filter_post_kses'); wp_update_post(array('ID' => $campaign->ID, 'post_content' => $placeholder->get_content(false))); //change status silencly if only bounces where sent $this->change_status($campaign, 'finished', $bounces_only); //do third party plugins stuff $this->thirdpartystuff(); } else { } if ($sent_this_turn) { do_action('mymail_cron_mails_sent', $campaign); } } } if ($cron_used && is_user_logged_in()) { $this->show_cron_log(); } if ($quit_cronjob && !$cron_used) { $this->remove_crons(); } do_action('mymail_cron_finished'); return true; }
selected($autoresponderdata['operator'], 'AND'); ?> title="<?php _e('and', 'mymail'); ?> "><?php _e('all of the conditions are true', 'mymail'); ?> </option> </select> </p> <?php if (!isset($autoresponderdata['conditions'])) { $autoresponderdata['conditions'] = array(array('field' => '', 'operator' => '', 'value' => '')); } $fields = apply_filters('mymail_autoresponder_condition_fields', array('email' => mymail_text('email'), 'firstname' => mymail_text('firstname'), 'lastname' => mymail_text('lastname'))); $i = 0; foreach ($autoresponderdata['conditions'] as $condition) { ?> <div class="mymail_autoresponder_condition" id="mymail_autoresponder_condition_<?php echo $i; ?> "> <select name="mymail_data[autoresponder][conditions][<?php echo $i; ?> ][field]"> <?php foreach ($fields as $value => $name) { echo '<option value="' . $value . '"' . selected($condition['field'], $value, false) . '>' . $name . '</option>'; }
echo $i++; ?> </td> <td><strong><a href="mailto:<?php echo $data['userdata']['email']; ?> "><?php echo $data['userdata']['email']; ?> </a></strong></td> <td><?php foreach ($data['userdata'] as $key => $value) { if (in_array($key, array('email', '_meta'))) { continue; } echo '<div><strong>' . mymail_text($key, isset($customfields[$key]) ? $customfields[$key]['name'] : $key) . '</strong>: ' . $value . '</div>'; } ?> </td> <td><?php foreach ($data['lists'] as $list) { $obj = get_term_by('slug', $list, 'newsletter_lists'); if ($obj) { echo '<div><a href="edit-tags.php?action=edit&taxonomy=newsletter_lists&tag_ID=' . $obj->term_id . '&post_type=newsletter">' . $obj->name . '</a></div>'; } } ?> </td> <td><strong><?php echo sprintf(__('%s ago', 'mymail'), human_time_diff($data['timestamp'])); ?>
public function comment_form_checkbox() { $commenter = wp_get_current_commenter(); if (!empty($commenter['comment_author_email'])) { if ($this->get_by_mail($commenter['comment_author_email'])) { return false; } } $field = '<p class="comment-form-newsletter-signup">'; $field .= '<label for="mymail_newsletter_signup"><input name="newsletter_signup" type="checkbox" id="mymail_newsletter_signup" value="1" ' . checked(mymail_option('register_comment_form_checked'), true, false) . '/> ' . mymail_text('newsletter_signup') . '</label>'; $field .= '</p>'; echo apply_filters("comment_form_field_newsletter_signup", $field) . "\n"; }