function __construct() { global $status, $page; $this->schedules = WPEM_Schedules::get_schedules(); $this->schedule_stgs = WPEM()->modules['settings']->settings['schedule']; $this->send_time = $this->schedule_stgs['send_time']['hh'] * 3600 + $this->schedule_stgs['send_time']['mn'] * 60; //Set parent defaults parent::__construct(array('singular' => 'schedule', 'plural' => 'schedules', 'ajax' => false)); }
/** * Fires a cron job at a specific time of day, rather than on an interval * */ public static function fire_schedule_jobs() { $send_time = WPEM()->modules['settings']->settings['schedule']['send_time']; $now = current_time('timestamp'); $trigger_time = strtotime(date('Y-m-d')) + $send_time['hh'] * 3600 + $send_time['mn'] * 60; $time_passed = $now - $trigger_time; if ($time_passed > 0 && $time_passed < 3600) { if (!get_transient('wpem_schedules_cron_job_complete')) { WPEM_Schedules::process_schedules(); set_transient('wpem_schedules_cron_job_complete', true, 60 * 70); //1 hour and 10 minutes transient } } }
/** * Defines the shortcode * * @mvc Controller * * @param array $attributes * return string */ public static function wpem_shortcode($attributes) { static $display_post; $attributes = apply_filters('wpem_shortcode-attributes', $attributes); $attributes = self::validate_shortcode_atts($attributes); if (isset($attributes['id'])) { if (!isset($display_post) || $display_post->ID != $attributes['id']) { $display_post = get_post($attributes['id']); } switch ($attributes[__('content', 'wpem')]) { case __('img', 'wpem'): $size = 'post-thumbnail'; if (isset($attributes['img_size'])) { $size = $attributes['img_size']; } return get_the_post_thumbnail($display_post->ID, $size); break; case __('title', 'wpem'): return $display_post->post_title; break; case __('post_link', 'wpem'): return get_permalink($display_post->ID); case __('title_link', 'wpem'): return '<a href="' . get_permalink($display_post->ID) . '">' . $display_post->post_title . '</a>'; break; case __('excerpt', 'wpem'): return $display_post->post_excerpt; break; case __('body', 'wpem'): return $display_post->post_content; break; } } elseif (isset($attributes[__('link', 'wpem')])) { switch ($attributes[__('link', 'wpem')]) { case __('unsubscribe', 'wpem'): $settings = WPEM()->modules['settings']->settings['user']; $location = add_query_arg('wpem_action', 'unsubscribe', get_permalink($settings['unsubscribe_page'])); return '<a href="' . $location . '">' . $settings['unsubscribe_text'] . '</a>'; break; } } elseif (isset($attributes[__('archive', 'wpem')]) && intval($attributes[__('archive', 'wpem')])) { $settings = WPEM()->modules['settings']->settings['mail']; return '<a href="' . site_url('/?' . __('wpem_browser_mail', 'wpem') . '=' . $attributes[__('archive', 'wpem')]) . '">' . $settings['show_in_browser_text'] . '</a>'; break; } }
$matches[] = array('label' => $full_names . ' (' . $user->user_login . ')' . '<' . $user->user_email . '>', 'value' => $value, 'email' => $user->user_email); } if (count($matches) == 100) { break; } } if (!empty($matches)) { $json = $matches; } else { $json = array('label' => __('No Matches', 'Zanto'), 'value' => ''); } echo json_encode($json); die; break; case 'test_mail': $ms = WPEM()->modules['settings']->settings['mail']; $mail['source'] = array('id' => 'sm'); $mail['mail_format'] = $_REQUEST['m_format']; $mail['from_email'] = !empty($ms['from_sender_email']) ? $ms['from_sender_email'] : get_option('admin_email'); $mail['from_name'] = !empty($ms['from_sender_name']) ? $ms['from_sender_name'] : get_bloginfo('name'); $mail['title'] = __('Test Mail', 'wpem'); $mail['body'] = $_REQUEST['m_body']; $mail['template'] = $_REQUEST['temp_id']; $current_user = get_user_by('id', get_current_user_id()); $full_names = !empty($current_user->first_name) || !empty($current_user->last_name) ? ucfirst($current_user->first_name) . ' ' . ucfirst($current_user->last_name) : $current_user->display_name; $mail['to_email'] = $current_user->user_email; $mail['to_name'] = $full_names; $json = array(); try { $mail = EM_Mailer::send_mail($mail); if (is_integer($mail)) {
public static function send_mail($mail) { $mail_stgs = WPEM()->modules['settings']->settings; $mail['recepients'] = self::get_recepients($mail); $mail = self::validate_mail($mail); $errors = $mail['errors']; if ($errors->get_error_code()) { return $mail; } $omit_name = $mail_stgs['mail']['omit_display_names']; // Default the To: and Cc: values to the send email address $to = $omit_name ? $mail['from_email'] : sprintf('%s <%s>', $mail['from_name'], $mail['from_email']); $cc = sprintf('Cc: %s', $to); $headers = array(); // Cc: Sender? $ccsender = $mail_stgs['mail']['copy_sender']; if ($ccsender) { $cc = sprintf('Cc: %s', $to); $headers[] = $cc; } $num_sent = 0; // return value if (empty($mail['recepients'])) { return $num_sent; } // Return path defaults to sender email if not specified $return_path = $mail_stgs['mail']['bounces_address']; if ($return_path == '') { $return_path = $mail['from_email']; } // Build headers $headers[] = $omit_name ? 'From: ' . $mail['from_email'] : sprintf('From: "%s" <%s>', $mail['from_name'], $mail['from_email']); $headers[] = sprintf('Return-Path: <%s>', $return_path); $headers[] = $omit_name ? 'Reply-To: ' . $mail['from_email'] : sprintf('Reply-To: "%s" <%s>', $mail['from_name'], $mail['from_email']); if ($mail_stgs['headers']['x_mailer']) { $headers[] = sprintf('X-Mailer: PHP %s', phpversion()); } $subject = apply_filters('wpem_mail_title', stripslashes($mail['title'])); $message = apply_filters('wpem_mail_body', do_shortcode(stripslashes($mail['body']))); $attachments = array(); if (isset($mail['attachments']) && !empty($mail['attachments'])) { foreach ($mail['attachments'] as $files) { $attachments[] = $files['attachment']; } } if ('html' == $mail['mail_format']) { if ($mail_stgs['headers']['mime']) { //add mime version_header $headers[] = 'MIME-Version: 1.0'; } $headers[] = sprintf('Content-Type: %s; charset="%s"', get_bloginfo('html_type'), get_bloginfo('charset')); $style = ''; if (isset($mail['template']) && absint($mail['template']) && intval($mail['template']) != -1) { $css = get_post_meta(intval($mail['template']), 'wpem_css-box-field', true); if (!empty($css)) { $style = '<style>' . $css . '</style>'; } } if (isset($css) && !empty($css) && $mail_stgs['mail']['inline_style']) { require_once WPEM_PLUGIN_PATH . '/classes/Emogrifier.php'; $html = '<html><head><title>' . $subject . '</title></head><body>' . $message . '</body></html>'; $emogrifier = new \Pelago\Emogrifier($html, $css); $mailtext = $emogrifier->emogrify(); } else { $mailtext = '<html><head><title>' . $subject . '</title>' . $style . '</head><body>' . $message . '</body></html>'; } } else { if ($mail_stgs['headers']['mime']) { $headers[] = 'MIME-Version: 1.0'; } $headers[] = sprintf('Content-Type: text/plain; charset="%s"', get_bloginfo('charset')); $message = preg_replace('|&[^a][^m][^p].{0,3};|', '', $message); $message = preg_replace('|&|', '&', $message); $mailtext = wordwrap(strip_tags($message . "\n" . $footer), 80, "\n"); } $recepients = self::format_recepients($mail['recepients'], $mail_stgs['mail']['max_bcc_recipients'], $omit_name); /* if (WPEM_DEBUG) { wpem_preprint(array_merge($headers, $bcc)); wpem_debug_wp_mail($to, $subject, $mailtext, array_merge($headers, $bcc)); } */ remove_filter('wp_mail', __CLASS__ . '::add_default_template'); if ($mail_stgs['mail']['max_bcc_recipients'] == -1) { $to = array_unique($to); $num_sent = count($recepients['to']); foreach ($recepients['to'] as $to) { @wp_mail($to, $subject, $mailtext, $headers, $attachments); } } else { foreach ($recepients['bcc'] as $bcc) { $bcc = array_unique($bcc); $num_sent = $num_sent + count($bcc); $to = ltrim(array_shift($bcc), "Bcc: "); @wp_mail($to, $subject, $mailtext, array_merge($headers, $bcc), $attachments); } } add_filter('wp_mail', __CLASS__ . '::add_default_template'); return $num_sent; }
/** * Creates the markup for the Settings page * * @mvc Controller */ public static function markup_settings_page() { global $EM_Mailer; if (current_user_can(self::REQUIRED_CAPABILITY)) { if (isset($_GET['mail_scope'])) { switch ($_GET['mail_scope']) { case 'settings': echo self::render_template('wpem-pages/settings.php'); break; case 'schedules': WPEM()->modules['schedules']->render_schedules(); break; case 'notifications': WPEM()->modules['notifications']->render_notifications(); break; case 'edit-schedule': break; default: $templates = get_posts(array('post_type' => 'wpem-temps')); echo self::render_template('wpem-pages/send-mail.php', array('templates' => $templates, 'mail' => $EM_Mailer->submit_results)); break; } } else { $templates = get_posts(array('post_type' => 'wpem-temps')); echo self::render_template('wpem-pages/send-mail.php', array('templates' => $templates, 'mail' => $EM_Mailer->get_submit_results())); } } else { wp_die('Access denied.'); } }