function wp_notify_postauthor($comment_id)
 {
     global $sunshine;
     $comment = get_comment($comment_id);
     $order = get_post($comment->comment_post_ID);
     if (!is_admin() && get_post_type($order) == 'sunshine-order') {
         $customer_id = get_post_meta($order->ID, '_sunshine_customer_id', true);
         $customer = get_user_by('id', $customer_id);
         $search = array('[comment]', '[order_id]', '[customer_name]');
         $replace = array(nl2br($comment->comment_content), $order->ID, $customer->first_name . ' ' . $customer->last_name);
         SunshineEmail::send_email('order_comment_admin', get_bloginfo('admin_email'), $sunshine->options['email_subject_order_comment'], $sunshine->options['email_subject_order_comment'], $search, $replace);
     }
 }
function sunshine_favorites_submit()
{
    global $sunshine, $current_user;
    if (isset($_GET['submit_favorites']) && isset($_GET['nonce']) && wp_verify_nonce($_GET['nonce'], 'sunshine_submit_favorites')) {
        $content = sprintf(__('%s has submitted their favorites, <a href="%s">view them here</a>', 'sunshine'), $current_user->display_name, admin_url('user-edit.php?user_id=' . $current_user->ID . '#sunshine-favorites'));
        $search = array('[message_content]');
        $replace = array($content);
        if ($sunshine->options['order_notifications']) {
            $admin_emails = explode(',', $sunshine->options['order_notifications']);
        } else {
            $admin_emails = array(get_bloginfo('admin_email'));
        }
        foreach ($admin_emails as $admin_email) {
            $mail_result = SunshineEmail::send_email('favorites', trim($admin_email), sprintf(__('%s has submitted favorites'), $current_user->display_name), '', $search, $replace);
        }
        $sunshine->add_message(__('Your favorite images have been sent', 'sunshine'));
        wp_redirect(sunshine_url('favorites'));
        exit;
    }
}
 public static function notify($order_id)
 {
     global $sunshine;
     $data = maybe_unserialize(get_post_meta($order_id, '_sunshine_order_data', true));
     $order_items = maybe_unserialize(get_post_meta($order_id, '_sunshine_order_items', true));
     $discount_items = maybe_unserialize(get_post_meta($order_id, '_sunshine_order_discounts', true));
     // Send confirmation email
     $th_style = 'padding: 0 20px 5px 0; border-bottom: 1px solid #CCC; text-align: left; font-size: 10px; color: #999; text-decoration: none;';
     $td_style = 'padding: 5px 20px 5px 0; text-align: left; font-size: 12px;';
     $items_html = '';
     $items_html = apply_filters('sunshine_before_order_receipt_items', $items_html, $order_id, $order_items);
     $items_html .= '<div class="order-items"><h3 style="font-size: 14px;">' . __('Cart Items', 'sunshine') . '</h3>';
     $items_html .= ' <table border="0" cellspacing="0" cellpadding="0" width="100%">';
     $items_html .= ' <tr><th style="' . $th_style . '">' . __('Image', 'sunshine') . '</th><th style="' . $th_style . '">' . __('Name', 'sunshine') . '</th><th style="' . $th_style . '">' . __('Quantity', 'sunshine') . '</th><th style="' . $th_style . '">' . __('Cost', 'sunshine') . '</th></tr>';
     foreach ($order_items as $key => $order_item) {
         $items_html .= ' <tr>';
         $thumb = wp_get_attachment_image_src($order_item['image_id'], 'sunshine-thumbnail');
         $image_html = '<img src="' . $thumb[0] . '" alt="" width="75" />';
         $items_html .= ' <td style="' . $td_style . '">' . apply_filters('sunshine_order_image_html', $image_html, $order_item, $thumb) . '</td>';
         $items_html .= ' <td style="' . $td_style . '">' . $order_item['product_name'] . '<br />' . apply_filters('sunshine_order_line_item_comments', $order_item['comments'], $order_id, $order_item) . '</td>';
         $items_html .= ' <td style="' . $td_style . '">' . $order_item['qty'] . '</td>';
         $items_html .= ' <td style="' . $td_style . '">' . sunshine_money_format($order_item['total'], false) . '</td>';
         $items_html .= ' </tr>';
     }
     $td_style .= ' font-weight: bold;';
     $th_style = 'padding: 0 20px 5px 0; text-align: left; font-size: 12px;';
     $items_html .= ' <tr><td colspan="3" style="' . $td_style . ' text-align: right; border-top: 2px solid #CCC;">' . __('Subtotal', 'sunshine') . '</td><td style="' . $td_style . ' border-top: 2px solid #CCC;">' . sunshine_money_format($data['subtotal'], false) . '</td></tr>';
     $items_html .= ' <tr><td colspan="3" style="' . $td_style . ' text-align: right;">' . __('Shipping', 'sunshine') . ' (' . sunshine_get_shipping_method_name($data['shipping_method']) . ')</td><td style="' . $td_style . '">' . sunshine_money_format($data['shipping_cost'], false) . '</td></tr>';
     if ($sunshine->options['tax_location'] && $sunshine->options['tax_rate']) {
         $items_html .= ' <tr><td colspan="3" style="' . $td_style . ' text-align: right;">' . __('Tax', 'sunshine') . '</td><td style="' . $td_style . '">' . sunshine_money_format($data['tax'], false) . '</td></tr>';
     }
     if ($data['discount_total'] > 0) {
         $items_html .= ' <tr><td colspan="3" style="' . $td_style . ' text-align: right;">' . __('Discounts', 'sunshine') . '</td><td style="' . $td_style . '">' . sunshine_money_format($data['discount_total'], false) . '</td></tr>';
     }
     if ($data['credits']) {
         $items_html .= ' <tr><td colspan="3" style="' . $td_style . ' text-align: right;">' . __('Credits', 'sunshine') . '</td><td style="' . $td_style . '">-' . sunshine_money_format($data['credits'], false) . '</td></tr>';
     }
     $items_html .= ' <tr><td colspan="3" style="' . $td_style . ' text-align: right; font-size: 16px;">' . __('Total', 'sunshine') . '</td><td style="' . $td_style . ' font-size: 16px;">' . sunshine_money_format($data['total'], false) . '</td></tr>';
     $items_html .= ' </table></div>';
     $customer_info = '<br /><br /><table border="0" cellspacing="0" cellpadding="0"><tr>';
     if ($data['country']) {
         $customer_info .= '<td class="billing-address" valign="top"><h3 style="font-size: 14px;">' . __('Billing Info', 'sunshine') . '</h3><p>';
         $customer_info .= $data['first_name'] . ' ' . $data['last_name'] . '<br>';
         $customer_info .= $data['address'];
         if ($data['address2']) {
             $customer_info .= '<br>' . $data['address2'];
         }
         $customer_info .= '<br>' . $data['city'] . ', ' . $data['state'] . ' ' . $data['zip'];
         if ($data['country']) {
             $customer_info .= '<br>' . $data['country'];
         }
         if ($data['email']) {
             $customer_info .= '<br>' . $data['email'];
         }
         if ($data['phone']) {
             $customer_info .= '<br>' . $data['phone'];
         }
         $customer_info .= '</p></td>';
     }
     if ($data['shipping_country']) {
         $customer_info .= '<td class="shipping-address" valign="top"><h3 style="font-size: 14px;">' . __('Shipping Info', 'sunshine') . '</h3><p>';
         $customer_info .= $data['shipping_first_name'] . ' ' . $data['shipping_last_name'] . '<br>';
         $customer_info .= $data['shipping_address'];
         if ($data['shipping_address2']) {
             $customer_info .= '<br>' . $data['shipping_address2'];
         }
         $customer_info .= '<br>' . $data['shipping_city'] . ', ' . $data['shipping_state'] . ' ' . $data['shipping_zip'];
         if ($data['shipping_country']) {
             $customer_info .= '<br>' . $data['shipping_country'];
         }
         $customer_info .= '</p></td>';
     }
     $customer_info .= '</tr></table>';
     $search = array('[message]', '[items]', '[customer_info]', '[order_id]', '[order_url]', '[first_name]', '[last_name]');
     $replace = array(nl2br($sunshine->options['email_receipt']), $items_html, $customer_info, $order_id, get_permalink($order_id), $data['first_name'], $data['last_name']);
     $mail_result = SunshineEmail::send_email('receipt', $data['email'], $sunshine->options['email_subject_order_receipt'], $sunshine->options['email_subject_order_receipt'], $search, $replace, $data);
     if ($sunshine->options['order_notifications']) {
         $admin_emails = explode(',', $sunshine->options['order_notifications']);
     } else {
         $admin_emails = array(get_bloginfo('admin_email'));
     }
     foreach ($admin_emails as $admin_email) {
         $mail_result = SunshineEmail::send_email('receipt_admin', trim($admin_email), sprintf(__('Order #%s placed on %s'), $order_id, get_option('blogname')), sprintf(__('<a href="%s">Order #%s</a> placed on %s'), admin_url('/post.php?post=' . $order_id . '&action=edit'), $order_id, get_option('blogname')), $search, $replace, $data);
     }
 }
function sunshine_init()
{
    global $sunshine;
    add_rewrite_endpoint($sunshine->options['endpoint_gallery'], EP_PERMALINK | EP_PAGES);
    add_rewrite_endpoint($sunshine->options['endpoint_image'], EP_PERMALINK | EP_PAGES);
    add_rewrite_endpoint($sunshine->options['endpoint_order'], EP_PERMALINK | EP_PAGES);
    SunshineUser::instance();
    SunshineCountries::instance();
    $functions = SUNSHINE_PATH . 'themes/' . $sunshine->options['theme'] . '/functions.php';
    if (file_exists($functions)) {
        include_once $functions;
    }
    if (is_admin()) {
        include_once 'admin/sunshine-admin.php';
    } else {
        SunshineSession::instance();
        SunshinePaymentMethods::instance();
        SunshineEmail::instance();
        SunshineFrontend::instance();
    }
}
function sunshine_order_comment_post($comment_id)
{
    global $sunshine;
    if (is_admin()) {
        $comment = get_comment($comment_id);
        $order = get_post($comment->comment_post_ID);
        $data = maybe_unserialize(get_post_meta($order->ID, '_sunshine_order_data', true));
        if (get_post_type($order) == 'sunshine-order') {
            $search = array('[comment]', '[order_id]', '[order_url]', '[first_name]', '[last_name]');
            $replace = array(nl2br($comment->comment_content), $order->ID, get_permalink($order->ID), $data['first_name'], $data['last_name']);
            SunshineEmail::send_email('order_comment', $data['email'], $sunshine->options['email_subject_order_comment'], $sunshine->options['email_subject_order_comment'], $search, $replace);
        }
    }
}