Exemplo n.º 1
0
 /**
  * Return an array of contact forms
  *
  * @param array $array
  *
  * @return array
  * @since  1.0
  * @author Francesco Licandro <*****@*****.**>
  */
 function yit_get_contact_forms($array = array())
 {
     if (!function_exists('YIT_Contact_Form')) {
         return array();
     }
     $posts = get_posts(array('post_type' => YIT_Contact_Form()->contact_form_post_type));
     foreach ($posts as $post) {
         $array[$post->post_name] = $post->post_title;
     }
     return $array;
 }
 function yith_ypop_get_contact_forms()
 {
     if (!function_exists('YIT_Contact_Form')) {
         return array('' => __('Plugin not activated or not installed', 'ypop'));
     }
     $array = array();
     $posts = get_posts(array('post_type' => YIT_Contact_Form()->contact_form_post_type));
     foreach ($posts as $post) {
         $array[$post->post_name] = $post->post_title;
     }
     if ($array == array()) {
         return array('' => __('No contact form found', 'ypop'));
     }
     return $array;
 }
Exemplo n.º 3
0
 /**
  * Enqueue style & script
  *
  * Enqueue frontend style and js script; constructor add it to wp_enqueue_script hook
  *
  * @return void
  * @since  1.0.0
  * @author Francesco Licandro <*****@*****.**>
  */
 public function enqueue_script()
 {
     wp_enqueue_script('contact-script', $this->plugin_assets_url . '/js/contact.min.js', array('jquery'), '', true);
     if (YIT_Contact_Form()->get('_nocaptcha_recaptcha') == '1') {
         wp_enqueue_script("ywqa-recaptcha", 'https://www.google.com/recaptcha/api.js');
     } else {
         wp_enqueue_script('captcha', $this->plugin_assets_url . '/js/google-api.js', false, '', true);
     }
     wp_enqueue_style('font-awesome', $this->plugin_assets_url . '/css/font-awesome.min.css');
     wp_localize_script('contact-script', 'contact_localization', array('url' => admin_url('admin-ajax.php'), 'wait' => __('Sending...', 'yit')));
 }
echo YIT_Contact_Form()->get('_submit_label');
?>
"
                       class="yit_sendemail <?php 
echo $button_style . ' ' . YIT_Contact_Form()->get('_submit_alignment');
?>
"/>
                <?php 
wp_nonce_field('yit-sendmail', 'yit_contact_form_nonce');
?>
                <div class="clear"></div>
            </li>
        </ul>
    </fieldset>
    <?php 
$error_align = YIT_Contact_Form()->get('_submit_alignment') == 'alignleft' ? 'error-right' : '';
?>
    <div class="contact-form-error-messages <?php 
echo $error_align;
?>
 col-sm-3">
        <?php 
foreach ($js_messages as $id => $msg) {
    if (isset($msg) && $msg != '') {
    }
    ?>
                <div class="contact-form-error-<?php 
    echo $id;
    ?>
 contact-form-error"><?php 
    echo $msg;
 /**
  * Send the email if the form is submitted
  *
  * @since 1.0.0
  * @author Francesco Licandro <*****@*****.**>
  */
 public function send_email()
 {
     $messages = $attachments = array();
     $qstr = '';
     //        if ( isset( $_POST['yit_bot'] ) && ! empty( $_POST['yit_bot'] ) )
     //            return;
     if (isset($_POST['yit_action']) and ($_POST['yit_action'] == 'sendemail' or $_POST['yit_action'] == 'sendemail-ajax') and wp_verify_nonce($_REQUEST['_wpnonce'], 'yit-sendmail')) {
         $this->current_form_id = intval($_POST['id_form']);
         // post_id
         if ($this->get('_captcha') == '1') {
             require_once YIT_Contact_Form()->plugin_path . '/vendors/recaptchalib.php';
             $privatekey = $this->get('_private_key');
             $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
             if (!$resp->is_valid) {
                 $this->_is_captcha_invalid = true;
                 return;
             } else {
                 $this->_is_captcha_invalid = false;
             }
         }
         $fields = $this->get('_items');
         //get the fields
         // body
         $body = nl2br($this->get('_body'));
         $yit_referer = $_POST['yit_referer'];
         // add ip and referer
         $shortcodes = apply_filters('yit_contact_form_shortcodes', array('%ipaddress%' => $_SERVER['REMOTE_ADDR'], '%referer%' => $yit_referer));
         foreach ($shortcodes as $shortcode => $val) {
             $body = str_replace($shortcode, $val, $body);
         }
         $union_qstr = $qstr == '' ? '?' : '';
         $reply_to = '';
         // to
         $to = $this->get('_receiver');
         // from
         $from_email = $this->get('_sender_mail');
         $from_name = $this->get('_sender_name');
         /// subject
         $subject = stripslashes($this->get('_subject'));
         $post_data = isset($_POST['yit_contact']) ? array_map('stripslashes_deep', $_POST['yit_contact']) : array();
         // sku
         if (isset($post_data['sku']) && isset($post_data['product_id'])) {
             $body = str_replace("%sku%", $post_data['sku'], $body);
             $body = str_replace("%product_id%", $post_data['product_id'], $body);
         }
         foreach ($fields as $c => $field) {
             $id = $field['data_name'];
             $type = $field['type'];
             if ($type == 'file') {
                 continue;
             }
             if ($field['type'] == 'checkbox' && isset($field['required']) && !isset($post_data[$id])) {
                 $this->messages[$this->current_form_id][$id] = stripslashes($field['error']);
             }
             if (isset($post_data[$id])) {
                 $var = $post_data[$id];
             }
             // validate, adding message error, set up on admin panel, if var is not valid.
             if (isset($field['required']) and $var == '' or isset($field['is_email']) and !is_email($var)) {
                 $this->messages[$this->current_form_id][$id] = stripslashes($field['error']);
             }
             // if reply to
             if (isset($field['reply_to']) and $field['reply_to'] == 'yes' || $field['reply_to'] == '1') {
                 $reply_to = $var;
             }
             // convert \n to <br>
             if (isset($field['type']) and $field['type'] == 'textarea') {
                 $var = nl2br($var);
             }
             ${$id} = $var;
             // replace tags of body config
             $body = str_replace("%{$id}%", $var, $body);
             $to = str_replace("%{$id}%", $var, $to);
             $from_email = str_replace("%{$id}%", $var, $from_email);
             $from_name = str_replace("%{$id}%", $var, $from_name);
             $subject = str_replace("%{$id}%", $var, $subject);
         }
         /*
                     var_dump($body);
                     var_dump($to);
                     var_dump($from_email);
                     var_dump($from_name);
                     var_dump($subject);
         */
         // if there ware some errors, return messages.
         if (!empty($this->messages[$this->current_form_id])) {
             return;
         }
         // if there are attachments
         if (isset($_FILES['yit_contact']['tmp_name'])) {
             foreach ($_FILES['yit_contact']['tmp_name'] as $id => $a_file) {
                 $file = basename($_FILES['yit_contact']['name'][$id]);
                 list($file_name, $file_ext) = explode('.', $file);
                 if (in_array($file_ext, array('php', 'js', 'exe', 'sh', 'bat', 'com'))) {
                     continue;
                 }
                 $new_path = WP_CONTENT_DIR . '/uploads/' . basename($_FILES['yit_contact']['name'][$id]);
                 move_uploaded_file($a_file, $new_path);
                 $attachments[] = $new_path;
             }
         }
         // set content type
         add_filter('wp_mail_content_type', create_function('$content_type', "return 'text/html';"));
         add_filter('wp_mail_from', create_function('$from', "return '{$from_email}';"));
         add_filter('wp_mail_from_name', create_function('$from', "return '{$from_name}';"));
         // all header, that will be print with implode.
         $headers = array();
         if ($reply_to) {
             $headers[] = 'Reply-To: ' . $reply_to;
         }
         if (wp_mail($to, $subject, $body, implode("\r\n", $headers), $attachments)) {
             $this->messages[$this->current_form_id]['general'] = '<div class="success"><p>' . $this->get('_success_sending') . '</p></div>';
             do_action('yit-sendmail-success');
         } else {
             $this->messages[$this->current_form_id]['general'] = '<p class="error">' . $this->get('_error_sending') . '</p>';
         }
     }
 }
/**
 * Get list of forms by YIT Contact Form plugin
 *
 * @param   $array array
 * @since   1.0.0
 * @author  Emanuela Castorina
 * @return  array
 */
function yith_ywraq_get_contact_forms()
{
    if (!function_exists('YIT_Contact_Form')) {
        return array('' => __('Plugin not activated or not installed', 'yith-woocommerce-request-a-quote'));
    }
    $posts = get_posts(array('post_type' => YIT_Contact_Form()->contact_form_post_type));
    foreach ($posts as $post) {
        $array[$post->post_name] = $post->post_title;
    }
    if ($array == array()) {
        return array('' => __('No contact form found', 'ywctm'));
    }
    return $array;
}