Esempio n. 1
0
 /**
  * The singleton access method
  *
  * @author Jonathan Davis
  * @since
  *
  * @return
  **/
 public static function init()
 {
     if (!self::$object instanceof self) {
         self::$object = new self();
     }
     return self::$object;
 }
Esempio n. 2
0
 /**
  * Sends an email message based on a specified template file
  *
  * Sends an e-mail message in the format of a specified e-mail
  * template file using variable substitution for variables appearing in
  * the template as a bracketed [variable] with data from the
  * provided data array or the super-global $_POST array
  *
  * @author Jonathan Davis
  * @since 1.0
  *
  * @param string $template Email template file path (or a string containing the template itself)
  * @param array $data The data to populate the template with
  * @return boolean True on success, false on failure
  **/
 public static function email($template, array $data = array())
 {
     $debug = defined('SHOPP_DEBUG_EMAIL') && SHOPP_DEBUG_EMAIL;
     $headers = array();
     $to = $subject = $message = '';
     $addrs = array('from', 'sender', 'reply-to', 'to', 'cc', 'bcc');
     $protected = array_merge($addrs, array('subject'));
     if (false == strpos($template, "\n") && file_exists($template)) {
         $templatefile = $template;
         // Include to parse the PHP and Theme API tags
         ob_start();
         ShoppStorefront::intemplate($templatefile);
         include $templatefile;
         ShoppStorefront::intemplate('');
         $template = ob_get_clean();
         if (empty($template)) {
             return shopp_add_error(Shopp::__('Could not open the email template because the file does not exist or is not readable.'), SHOPP_ADMIN_ERR, array('template' => $templatefile));
         }
     }
     // Sanitize line endings
     $template = str_replace(array("\r\n", "\r"), "\n", $template);
     $lines = explode("\n", $template);
     // Collect headers
     while ($line = array_shift($lines)) {
         if (false === strpos($line, ':')) {
             continue;
         }
         // Skip invalid header lines
         list($header, $value) = explode(':', $line, 2);
         $header = strtolower($header);
         if (in_array($header, $protected)) {
             // Protect against header injection
             $value = str_replace(array("\n", "\r"), '', rawurldecode($value));
         }
         if (in_array($header, array('to', 'subject'))) {
             $headers[$header] = trim($value);
         } else {
             $headers[$header] = $line;
         }
     }
     $message = join("\n", $lines);
     // If not already in place, setup default system email filters
     ShoppEmailDefaultFilters::init();
     // Message filters first
     $message = apply_filters('shopp_email_message', $message, $headers);
     $headers = apply_filters('shopp_email_headers', $headers, $message);
     $to = $headers['to'];
     unset($headers['to']);
     $subject = $headers['subject'];
     unset($headers['subject']);
     $sent = wp_mail($to, $subject, $message, $headers);
     do_action('shopp_email_completed');
     if ($debug) {
         shopp_debug("To: " . htmlspecialchars($to) . "\n");
         shopp_debug("Subject: {$subject}\n\n");
         shopp_debug("Headers:\n");
         shopp_debug("\nMessage:\n{$message}\n");
     }
     return $sent;
 }