/** * Split the $message into sections and apply the sections to the template * * @param string $message If passed, this will be used as the source of the sections * @return string The modified message with all the sections replaced */ public function apply_template($message = null) { if (is_null($message)) { $message = $this->message; } if (empty($this->template)) { // no template set. simply return the message return $message; } $tpl = new FUE_Email_Template($this->template); $sections = $tpl->get_sections(); $contents = $tpl->get_contents(); if (empty($contents)) { // nothing to process return $message; } foreach ($sections as $section) { $section_body = fue_str_search('{section:' . $section . '}', '{/section}', $message); if (!empty($section_body)) { $contents = str_replace('{section:' . $section . '}', $section_body[0], $contents); } } // remove unused sections from $contents foreach ($sections as $section) { $contents = str_replace('{section:' . $section . '}', '', $contents); } return apply_filters('fue_email_apply_template', $contents, $this); }
/** * Look for sections in self.contents and store them in self.sections */ private function extract_sections() { $sections = fue_str_search('{section:', '}', $this->contents); if (is_array($sections)) { $sections = array_filter(array_map('trim', $sections)); } else { $sections = array(); } $this->sections = $sections; }
/** * Determine the part to send for reminder emails * * @param string $message * @param FUE_Email $email * @param object $queue_item * * @return string */ public function parse_reminder_message($message, $email, $queue_item) { global $wpdb; if ($queue_item->order_id > 0 && $email->type == 'reminder') { // count the total emails and the number of sent emails $total_emails = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}followup_email_orders WHERE order_id = %d AND email_id = %d", $queue_item->order_id, $email->id)); $sent_emails = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}followup_email_orders WHERE order_id = %d AND email_id = %d AND is_sent = 1", $queue_item->order_id, $email->id)); if ($total_emails == 1) { $messages = fue_str_search('{first_email}', '{/first_email}', $message); $message = isset($messages[0]) ? $messages[0] : ''; } elseif ($total_emails == 2) { if ($sent_emails == 0) { $messages = fue_str_search('{first_email}', '{/first_email}', $message); $message = isset($messages[0]) ? $messages[0] : ''; } else { $messages = fue_str_search('{final_email}', '{/final_email}', $message); $message = isset($messages[0]) ? $messages[0] : ''; } } else { if ($sent_emails == 0) { $messages = fue_str_search('{first_email}', '{/first_email}', $message); $message = isset($messages[0]) ? $messages[0] : ''; } elseif ($sent_emails == $total_emails - 1) { $messages = fue_str_search('{final_email}', '{/final_email}', $message); $message = isset($messages[0]) ? $messages[0] : ''; } else { $messages = fue_str_search('{quantity_email}', '{/quantity_email}', $message); $message = isset($messages[0]) ? $messages[0] : ''; } } } return $message; }