예제 #1
0
function sn_shortcode_contact($atts)
{
    global $response;
    //user posted variables
    if (isset($_POST['submitted'])) {
        $name = $_POST['sn_name'];
        $email = $_POST['sn_email'];
        $message = $_POST['sn_message'];
        $human = $_POST['sn_title'];
    }
    //php mailer variables
    $to = of_get_option('sn_contact_email');
    if (!isset($to) || $to == '') {
        $to = get_option('admin_email');
    }
    if (isset($_POST['submitted'])) {
        //response messages
        $not_human = of_get_option('sn_contact_message_verification');
        $missing_content = of_get_option('sn_contact_message_content');
        $email_invalid = of_get_option('sn_contact_message_email');
        $message_unsent = of_get_option('sn_contact_message_notsent');
        $message_sent = of_get_option('sn_contact_message_sent');
        $message_body = of_get_option('sn_contact_email_body');
        // replace variables
        if (!empty($message_body)) {
            $message_body = str_replace('{name}', $name, $message_body);
            $message_body = str_replace('{email}', $email, $message_body);
            $message_body = str_replace('{message}', $message, $message_body);
            $message_body = str_replace('{site_name}', get_bloginfo('name'), $message_body);
        }
        // EMAIL LOGO
        $email_logo_url = of_get_option('sn_contact_email_logo');
        $email_logo = '';
        if ($email_logo_url) {
            $img_id = sn_get_attachment_id_from_src($email_logo_url);
            $img_logo = wp_get_attachment_image_src($img_id, 'full');
            // use image testimonial exist
            if ($img_logo) {
                $email_logo = '<img src="' . $img_logo[0] . '" width="' . $img_logo[1] . '" height="' . $img_logo[2] . '" alt="' . get_bloginfo('name') . '" />';
            } else {
                $email_logo = '<img src="' . esc_attr($email_logo_url) . '" alt="' . get_bloginfo('name') . '" />';
            }
        }
        $message_content = '
        <!DOCTYPE html>
        <html lang="cs">
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <meta name="Copyright" content="" />
                <meta name="Author" content="The Seniores, www.theseniores.com" />
                <meta name="Keywords" content="" />
                <meta name="Description" content="" />
                <title>Spacetype email</title>
            </head>
            <body style="padding:0; margin:0">
                <div style="margin:0; padding:25px 0; font-size:16px; font-family: Arial, sans-serif; color:#333333; line-height:24px; width:100%; text-align:center; background:#ededed;">
                    <table cellspacing="0" cellpadding="0" border="0" style="text-align:left; margin:0 auto; width:480px; border:1px solid #ddd; padding:0; font-size:12px; background:#fff;">
                        <tbody>
                            <tr>
                                <td style="margin:0; padding:15px 0;">
                                    <table cellspacing="0" cellpadding="0" border="0" style="width:100%; font-size:16px; font-family: Arial, sans-serif; padding:0; margin:0; line-height:24px;">
                                        <tbody>
                                            <tr>
                                                <td style="margin:0; padding:20px 0 20px; vertical-align:middle;text-align:center;">
                                                   ' . $email_logo . '
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    <table cellspacing="0" cellpadding="0" border="0" style="width:100%; font-size:16px; font-family: Arial, sans-serif; line-height:24px; padding:0 0 0 0; margin:0; color:#333333;">
                                        <tbody>
                                            <tr>
                                                <td style="margin:0; padding:15px 30px 0; vertical-align:top;">
                                                   ' . apply_filters('the_content', $message_body) . '
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </body>
        </html>
        ';
        $subject = sprintf(__('%1$s sent a message from %2$s website', 'sn'), $name, get_bloginfo('name'));
        $headers = 'MIME-Version: 1.0' . "\r\n";
        //$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'Content-type: text/html' . "\r\n";
        $headers .= 'From: ' . $name . ' <' . $to . '>' . "\r\n" . 'Reply-To: ' . $email;
        if (!empty($human)) {
            sn_generate_response("error", $not_human);
            //not human!
        } else {
            //validate presence of name, email and message
            if (empty($name) || empty($email) || empty($message)) {
                sn_generate_response("error", $missing_content);
            } else {
                //validate email
                if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                    sn_generate_response("error", $email_invalid);
                } else {
                    //ready to go!
                    $sent = wp_mail($to, $subject, $message_content, $headers);
                    if ($sent) {
                        sn_generate_response("success", $message_sent);
                        //message sent!
                    } else {
                        sn_generate_response("error", $message_unsent);
                        //message wasn't sent
                    }
                }
            }
        }
    }
    $form_name = isset($_POST['sn_name']) ? esc_attr($_POST['sn_name']) : '';
    $form_email = isset($_POST['sn_email']) ? esc_attr($_POST['sn_email']) : '';
    $form_message = isset($_POST['sn_message']) ? esc_attr($_POST['sn_message']) : '';
    $actual_url = getUrl();
    // form labels
    $label_name = of_get_option('sn_contact_info_name');
    $label_email = of_get_option('sn_contact_info_email');
    $label_message = of_get_option('sn_contact_info_message');
    $label_button = of_get_option('sn_contact_info_button');
    $output = '
        <div id="form-contact">
            ' . $response . '
            <form action="' . $actual_url . '#form-contact" method="post">
                <div class="grid">
                    <p class="col col-1-2">
                        <label for="sn_name" class="h6">' . $label_name . '</label>
                        <span class="inp-fix">
                            <input type="text" class="inp-text" id="sn_name" name="sn_name" value="' . $form_name . '" />
                        </span>
                    </p>
                    <p class="col col-1-2">
                        <label for="sn_email" class="h6">' . $label_email . '</label>
                        <span class="inp-fix">
                            <input type="text" class="inp-text" id="sn_email" name="sn_email" value="' . $form_email . '" />
                        </span>
                    </p>
                    <p class="col col-1-1">
                        <label for="sn_message" class="h6">' . $label_message . '</label>
                        <span class="inp-fix">
                            <textarea name="sn_message" id="sn_message" cols="30" rows="5" class="inp-text">' . $form_message . '</textarea>
                        </span>
                    </p>
                </div>
                <p style="display:none;">
                    <input type="hidden" name="submitted" value="1" />
                    <label for="sn_title" class="h6">' . __('Leave this field empty', 'sn') . '</label>
                    <span class="inp-fix">
                        <input type="text" class="inp-text" id="sn_title" name="sn_title" />
                    </span>
                </p>
                <p class="reset">
                    <button class="btn btn-s" type="submit"><span>' . $label_button . '</span></button>
                </p>
            </form>
        </div>
    ';
    return $output;
}
예제 #2
0
function sn_header_logo($get_logo_height = false)
{
    if (is_front_page()) {
        if (!is_home()) {
            $is_fixed = of_get_option('sn_header_fixed');
            if ($is_fixed == '1') {
                $logo_el_start = '<h1 id="logo"><a href="#main">';
            } else {
                $logo_el_start = '<h1 id="logo">';
            }
        } else {
            $logo_el_start = '<h1 id="logo">';
        }
    } else {
        $logo_el_start = '<p id="logo"><a href="' . home_url('/') . '">';
    }
    if (is_front_page()) {
        if (!is_home()) {
            $is_fixed = of_get_option('sn_header_fixed');
            if ($is_fixed == '1') {
                $logo_el_end = '</a><strong class="toggle-menu"><span class="icon icon-crossroad"></span></strong></h1>';
            } else {
                $logo_el_end = '<strong class="toggle-menu"><span class="icon icon-crossroad"></span></strong></h1>';
            }
        } else {
            $logo_el_end = '<strong class="toggle-menu"><span class="icon icon-crossroad"></span></strong></h1>';
        }
    } else {
        $logo_el_end = '</a><strong class="toggle-menu"><span class="icon icon-crossroad"></span></strong></p>';
    }
    // start logo el
    $img_logo = '';
    $output = $logo_el_start;
    $logo_url = of_get_option('sn_logo');
    $retina = of_get_option('sn_logo_retina');
    if ($logo_url) {
        $img_id = sn_get_attachment_id_from_src($logo_url);
        $img_logo = wp_get_attachment_image_src($img_id, 'full');
        $width = $retina ? $img_logo[1] / 2 : $img_logo[1];
        $height = $retina ? $img_logo[2] / 2 : $img_logo[2];
        if ($img_logo) {
            // use $img_logo array if exist
            $output .= '<img src="' . $img_logo[0] . '" width="' . $width . '" height="' . $height . '" alt="' . get_bloginfo('name') . '" />';
        } else {
            // use logo url
            $output .= '<img src="' . esc_attr($logo_url) . '" alt="' . get_bloginfo('name') . '" />';
        }
    } else {
        $output .= '<span>' . get_bloginfo('name') . '</span>';
    }
    // end logo el
    $output .= $logo_el_end;
    if ($get_logo_height) {
        if ($img_logo) {
            return $height;
        } else {
            return '';
        }
    } else {
        echo $output;
    }
}