/**
  * Features tab shortcode
  * 
  * @return string
  * @since 1.0.0
  */
 public function print_tab($name_or_id, $echo = true)
 {
     global $yit_is_feature_tab;
     $yit_is_feature_tab = true;
     $this->current_featurestab = is_int($name_or_id) ? $name_or_id : yit_post_id_from_slug($name_or_id, 'featurestab');
     $tab_id = yit_post_slug_from_id($this->current_featurestab);
     $fields = $this->get('fields');
     if (!is_array($fields) or empty($fields)) {
         return null;
     }
     $features_label = '';
     $features_content = '';
     $i = 0;
     foreach ($fields as $id => $field) {
         $current = !$i ? 'current-feature' : '';
         $the_label = '<li class="features-tab-' . $i . ' ' . $current . '">';
         if (!empty($field['icon'])) {
             $the_label .= '<img src="' . $field['icon'] . '" title="' . $field['title'] . '" alt="' . $field['title'] . '" />';
         }
         $the_label .= $field['title'];
         $the_label .= '</li>';
         $the_content = '<div class="features-tab-content features-tab-' . $i . ' ' . $current . '">' . yit_addp($field['content']) . '</div>';
         $features_label .= $the_label;
         $features_content .= $the_content;
         $i++;
     }
     $without_sidebar = yit_get_sidebar_layout() == 'sidebar-no' ? 'without-sidebar' : '';
     $html = '<div class="row">';
     $html .= '<div id="features-tab-' . $name_or_id . '" class="features-tab-container  group span' . (yit_get_sidebar_layout() == 'sidebar-no' ? '12' : '9') . ' margin-bottom">';
     $html .= '<div class="row">';
     $html = apply_filters('yit_before_features_tab_menu', $html);
     $html .= '<ul class="features-tab-labels span3">' . $features_label . '</ul>';
     $html .= '<div class="features-tab-wrapper span' . (yit_get_sidebar_layout() == 'sidebar-no' ? '9' : '6') . '">' . $features_content . '</div>';
     $html = apply_filters('yit_after_features_tab_content', $html);
     $html .= '</div>';
     $html .= '</div>';
     $html .= '</div>';
     if ($echo) {
         echo $html;
     }
     return $html;
     $yit_is_feature_tab = false;
 }
Example #2
0
 /**
  * Generate the module
  *
  * @since 1.0.0
  */
 public function module($name_or_id, $echo = true)
 {
     global $is_footer;
     $this->current_form = is_int($name_or_id) ? $name_or_id : yit_post_id_from_slug($name_or_id, 'contactform');
     $form_name = yit_post_slug_from_id($this->current_form);
     $fields = $this->get('fields');
     if (!is_array($fields) or empty($fields)) {
         return null;
     }
     $max_width = '';
     foreach ($fields as $id => $field) {
         preg_match('/[\\d]+/', $field['width'], $matches);
         if ($max_width < (int) $matches[0]) {
             $max_width = $matches[0];
         }
     }
     $html = '<form id="contact-form-' . $form_name . '" class="contact-form' . (!$is_footer ? ' row' : '') . '" method="post" action="" enctype="multipart/form-data">' . "\n\n";
     // div message feedback
     $html .= "\t<div class=\"usermessagea\">" . $this->_generalMessage($this->current_form, false) . "</div>\n";
     $html .= "\t<fieldset>\n\n";
     $html .= "\t\t<ul>\n\n";
     // array with all messages for js validate
     $js_messages = array();
     foreach ($fields as $id => $field) {
         // classes
         $input_class = array();
         // array for print input's classes
         $li_class = array($field['type'] . '-field');
         // array for print li's classes
         // errors
         $error_msg = '';
         $error = false;
         $js_messages[$field['data_name']] = $field['error'];
         if (isset($field['data_name'])) {
             $error_msg = $this->_getMessage($field['data_name']);
             if (!empty($error_msg)) {
                 $error = TRUE;
             }
         }
         // li class
         if ($field['class'] != '') {
             $li_class[] = " {$field['class']}";
         }
         if (isset($field['icon']) && $field['icon'] != '') {
             array_push($li_class, 'with-icon');
         }
         if ($error) {
             array_push($input_class, 'icon', 'error');
         }
         if (isset($field['icon']) && $field['icon'] != '') {
             array_push($input_class, 'with-icon');
         }
         $html .= "\t\t\t<li class=\"" . implode($li_class, ' ') . ' ' . $field['width'] . "\">\n";
         //Label
         if ($field['type'] != 'select') {
             if ($field['type'] != 'radio') {
                 $html .= "\t\t\t\t<label for=\"{$field['data_name']}-{$form_name}\">\n";
             } else {
                 $html .= "\t\t\t\t<label>\n";
             }
             $html .= yit_string("\t\t\t\t\t" . '<span class="mainlabel">', stripslashes_deep($field['title'], 'highlight-text'), '</span>' . "\n", false);
             $html .= yit_string("\t\t\t\t\t" . '<span class="sublabel">', stripslashes_deep($field['description']), '</span>' . "\n", false);
             $html .= "\t\t\t\t</label>\n";
         } else {
             if (isset($field['description']) || $field['description'] != '') {
                 $html .= "\t\t\t\t<label>\n";
                 $html .= yit_string("\t\t\t\t\t" . '<span class="sublabel">', stripslashes_deep($field['description']), '</span>' . "\n", false);
                 $html .= "\t\t\t\t</label>\n";
             }
             $field['options'] = array('the-form-label' => $field['title']) + $field['options'];
         }
         // if required
         if (isset($field['required']) and intval($field['required'])) {
             $input_class[] = 'required';
         }
         if (isset($field['is_email']) and intval($field['is_email'])) {
             $input_class[] = 'email-validate';
         }
         // retrive value
         if (isset($field['data_name']) && $error) {
             $value = $this->_postValue($field['data_name']);
         } else {
             if (isset($_GET[$field['data_name']])) {
                 $value = $_GET[$field['data_name']];
             } else {
                 $value = '';
             }
         }
         // only for clean code
         $html .= "\t\t\t\t";
         // Icon
         $html .= "<div class=\"input-prepend\">";
         if (isset($field['icon']) && $field['icon'] != '') {
             if (filter_var($field['icon'], FILTER_VALIDATE_URL)) {
                 $html .= "<span class=\"add-on\"><img src=\"" . $field['icon'] . "\" alt=\"\" title=\"\" /></span>";
             } else {
                 $html .= "<span class=\"add-on\"><i class=\"icon-" . $field['icon'] . "\"></i></span>";
             }
         }
         // print type of input
         switch ($field['type']) {
             // text
             case 'text':
                 $html .= "<input type=\"text\" name=\"yit_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-{$form_name}\" class=\"" . implode($input_class, ' ') . "\" value=\"{$value}\" />";
                 break;
                 // hidden
             // hidden
             case 'hidden':
                 $html .= "<input type=\"hidden\" name=\"yit_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-{$form_name}\" class=\"" . implode($input_class, ' ') . "\" value=\"{$value}\" />";
                 break;
                 // checkbox
             // checkbox
             case 'checkbox':
                 $checked = '';
                 if ($value != '' and $value) {
                     $checked = ' checked="checked"';
                 } else {
                     if (isset($field['already_checked']) && intval($field['already_checked'])) {
                         $checked = ' checked="checked"';
                     }
                 }
                 $html .= "<input type=\"checkbox\" name=\"yit_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-{$form_name}\" value=\"1\" class=\"" . implode($input_class, ' ') . "\"{$checked} />";
                 if (isset($field['label_checkbox'])) {
                     $html .= ' ' . $field['label_checkbox'];
                 }
                 break;
                 // select
             // select
             case 'select':
                 $html .= "<select name=\"yit_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-{$form_name}\" class=\"" . implode($input_class, ' ') . "\">\n";
                 // options
                 foreach ($field['options'] as $id => $option) {
                     $selected = '';
                     if (isset($field['option_selected']) && $field['option_selected'] == $id) {
                         $selected = ' selected="selected"';
                     }
                     if ($id === 'the-form-label') {
                         $html .= "\t\t\t\t\t\t<option value=\"\"{$selected}>{$option}</option>\n";
                     } else {
                         $html .= "\t\t\t\t\t\t<option value=\"{$option}\"{$selected}>{$option}</option>\n";
                     }
                 }
                 $html .= "\t\t\t\t\t</select>";
                 break;
                 // textarea
             // textarea
             case 'textarea':
                 $html .= "<textarea name=\"yit_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-{$form_name}\" rows=\"8\" cols=\"30\" class=\"" . implode($input_class, ' ') . "\">{$value}</textarea>";
                 break;
                 // radio
             // radio
             case 'radio':
                 // options
                 foreach ($field['options'] as $i => $option) {
                     $selected = '';
                     if (isset($field['option_selected']) && $field['option_selected'] == $i) {
                         $selected = ' checked=""';
                     }
                     $html .= "\t\t\t\t\t\t<input type=\"radio\" name=\"yit_contact[{$field['data_name']}]\" id=\"{$field['data_name']}-{$form_name}-{$i}\" value=\"{$option}\"{$selected} /><label for=\"{$field['data_name']}-{$form_name}-{$i}\">{$option}</label>\n";
                 }
                 $html .= "\t\t\t\t<div class=\"clear\"></div>\n";
                 break;
                 // password
             // password
             case 'password':
                 $html .= "<input type=\"password\" name=\"yit_contact[{$field['data_name']}]\" id=\"{$field['data_name']}-{$form_name}\" class=\"" . implode($input_class, ' ') . "\" value=\"{$value}\" />";
                 break;
                 // file
             // file
             case 'file':
                 $html .= "<input type=\"file\" name=\"yit_contact[{$field['data_name']}]\" id=\"{$field['data_name']}-{$form_name}\" class=\"" . implode($input_class, ' ') . "\" />";
                 break;
         }
         // Icon
         $html .= "</div>";
         // only for clean code
         $html .= "\n";
         $html .= "\t\t\t\t<div class=\"msg-error\">" . $error_msg . "</div><div class=\"clear\"></div>\n";
         $html .= "\t\t\t</li>\n";
     }
     $html .= "\t\t\t<li class=\"submit-button span" . $max_width . "\">\n";
     $html .= "\t\t\t\t<div style=\"position:absolute;left:-9999px;\"><input type=\"text\" name=\"email_check_2\" id=\"email_check_2\" value=\"\" /></div>\n";
     $html .= "\t\t\t\t<input type=\"hidden\" name=\"yit_action\" value=\"sendemail\" id=\"yit_action\" />\n";
     $html .= "\t\t\t\t<input type=\"hidden\" name=\"yit_referer\" value=\"" . yit_curPageURL() . "\" />\n";
     $html .= "\t\t\t\t<input type=\"hidden\" name=\"id_form\" value=\"{$this->current_form}\" />\n";
     $html .= "\t\t\t\t<input type=\"submit\" name=\"yit_sendemail\" value=\"" . $this->get('submit_label') . "\" class=\"sendmail " . $this->get('submit_alignment') . "\" />";
     $html .= "\t\t\t\t<div class=\"clear\"></div>";
     $html .= "\t\t\t</li>\n";
     $html .= "\t\t</ul>\n\n";
     $html .= "\t</fieldset>\n";
     $html .= "</form>\n\n";
     // messages for javascript validation
     $html .= "<script type=\"text/javascript\">\n";
     $html .= "\tvar messages_form_" . $this->current_form . " = {\n";
     foreach ($js_messages as $id => $msg) {
         $html .= "\t\t{$id}: \"{$msg}\",\n";
     }
     // remove last comma
     $html = str_replace("\t\t{$id}: \"{$msg}\",\n", "\t\t{$id}: \"{$msg}\"\n", $html);
     $html .= "\t};\n";
     $html .= "</script>";
     if ($echo) {
         echo $html;
     }
     return $html;
 }
Example #3
0
    /**
     * Generate the module
     *
     * @since 1.0.0
     */
    public function module( $name_or_id, $action, $echo = true )
    {
        global $is_footer;

        $this->current_form = is_int( $name_or_id ) ? $name_or_id : yit_post_id_from_slug( $name_or_id, 'contactform' );
        $form_name = yit_post_slug_from_id( $this->current_form );

        $general_message = $this->_generalMessage( $this->current_form, false );

        $fields = $this->get('fields');


        if( !is_array( $fields ) OR empty( $fields ) )
            return null;

        $max_width = '';
        foreach( $fields as $id => $field ) {
            preg_match( '/[\d]+/', $field['width'], $matches );

            if( $max_width < ( int ) $matches[0] )
            { $max_width = $matches[0]; }
        }

        $html = '<form id="contact-form-' . $form_name . '" class="contact-form' . ( !$is_footer ? ' row-fluid' : '' ) .'" method="post" action="'.$action.'" enctype="multipart/form-data">' . "\n\n";

        // div message feedback
        $html .= "\t<div class=\"usermessagea\">" . $general_message . "</div>\n";

        $html .= "\t<fieldset>\n\n";
        $html .= "\t\t<ul>\n\n";

        // array with all messages for js validate
        $js_messages = array();

        $current_total_width = 0; $i = 0;
        foreach( $fields as $id => $field )
        {
            // classes
            $input_class = array();   // array for print input's classes
            $li_class = array( $field['type'] . '-field' );    // array for print li's classes

            // errors
            $error_msg = '';
            $error = false;
            $js_messages[ $field['data_name'] ] = $field['error'];

            if ( isset( $field['data_name'] ) )
            {
                $error_msg = $this->_getMessage( $field['data_name'] );
                if ( ! empty( $error_msg ) ) $error = TRUE;
            }

            // li class
            if( $field['class'] != '' )
                $li_class[] = " $field[class]";

            if ( isset( $field['icon'] ) && $field['icon'] != '' )
                array_push( $li_class, 'with-icon');

            /** Clear left margin for first element */
            /*
            $current_total_width = $current_total_width + str_replace('span','',$field['width']);
            if ( $current_total_width > 12 ) {
                $current_total_width = str_replace('span','',$field['width']);
                array_push( $li_class, 'first-of-line');
            }
            */

            if( $error )
                array_push( $input_class, 'icon', 'error' );

            if ( isset( $field['icon'] ) && $field['icon'] != '' ) {
                array_push( $input_class, 'with-icon');
            }


            $html .= "\t\t\t<li class=\"" . implode( $li_class, ' ' ) . ' ' . $field['width'] . "\">\n";

            //Label
            /*
            if( $field['type'] != 'select' ) {
				if( $field['type'] != 'radio' )
        			$html .= "\t\t\t\t<label for=\"$field[data_name]-$form_name\">\n";
				else
					$html .= "\t\t\t\t<label>\n";

        		$html .= yit_string( "\t\t\t\t\t" . '<span class="mainlabel">', stripslashes_deep( $field['title'], 'highlight-text' ), '</span>' . "\n", false );
				if( isset( $field['required'] ) )
					$html .= "\t\t\t\t\t" . '<span class="required">' . __('(required)','yit') . '</span>' . "\n";
        		$html .= yit_string( "\t\t\t\t\t" . '<span class="sublabel">', stripslashes_deep( $field['description'] ), '</span>' . "\n", false );

        		$html .= "\t\t\t\t</label>\n";
            } else {
				if(isset($field['description']) || $field['description'] != '') {
					$html .= "\t\t\t\t<label>\n";
					if( isset( $field['required'] ) )
						$html .= "\t\t\t\t\t" . '<span class="required">' . __('(required)','yit') . '</span>' . "\n";
	        		$html .= yit_string( "\t\t\t\t\t" . '<span class="sublabel">', stripslashes_deep( $field['description'] ), '</span>' . "\n", false );
	        		$html .= "\t\t\t\t</label>\n";
				}
                $field['options'] = array( 'the-form-label' =>  $field['title'] ) + $field['options'];
            }
			*/

            // if required
            if( isset( $field['required'] ) AND intval( $field['required'] ) )
                $input_class[] = 'required';

            if( isset( $field['is_email'] ) AND intval( $field['is_email'] ) )
                $input_class[] = 'email-validate';



            // retrive value
            if( isset( $field['data_name'] ) && ( empty( $general_message ) || $error ) )
                $value = $this->_postValue( $field['data_name'] );
            else if ( isset( $_GET[ $field['data_name'] ] ) )
                $value = $_GET[ $field['data_name'] ];
            else
                $value = '';

            // only for clean code
            $html .= "\t\t\t\t";

            // Icon
            $html .= "<div class=\"input-prepend\">";
            if ( isset( $field['icon'] ) && $field['icon'] != '' ) {
                if( filter_var( $field['icon'], FILTER_VALIDATE_URL ) )
                { $html .= "<span class=\"add-on\"><img src=\"". $field['icon'] . "\" alt=\"\" title=\"\" /></span>"; }
                else
                { $html .= "<span class=\"add-on\"><i class=\"icon-" . $field['icon'] . "\"></i></span>"; }
            }

            // print type of input
            switch( $field['type'] )
            {
                // text
                case 'text':
                    $html .= "<input type=\"text\" name=\"yit_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-$form_name\" class=\"" . implode( $input_class, ' ' ) . "\" value=\"$value\" placeholder=\"" . stripslashes_deep( $field['title'], 'highlight-text' ) . "\" />";
                    break;

                // hidden
                case 'hidden':
                    $html .= "<input type=\"hidden\" name=\"yit_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-$form_name\" class=\"" . implode( $input_class, ' ' ) . "\" value=\"$value\" />";
                    break;

                // checkbox
                case 'checkbox':
                    $checked = '';

                    if( $value != '' AND $value )
                        $checked = ' checked="checked"';
                    else if( isset($field['already_checked']) && intval( $field['already_checked'] ) )
                        $checked = ' checked="checked"';

                    $html .= "<input type=\"checkbox\" name=\"yit_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-$form_name\" value=\"1\" class=\"" . implode( $input_class, ' ' ) . "\"{$checked} />";
                    if ( isset( $field['title'] ) ) $html .= ' ' . $field['title'];
                    break;

                // select
                case 'select':
                    $html .= "<select name=\"yit_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-$form_name\" class=\"" . implode( $input_class, ' ' ) . "\">\n";

                    // options
                    foreach( $field['options'] as $id => $option )
                    {
                        $selected = '';
                        if( isset($field['option_selected']) && $field['option_selected'] == $id )
                            $selected = ' selected="selected"';

                        if( $id === 'the-form-label' ) {
                            $html .= "\t\t\t\t\t\t<option value=\"\"$selected>$option</option>\n";
                        } else {
                            $html .= "\t\t\t\t\t\t<option value=\"$option\"$selected>$option</option>\n";
                        }
                    }

                    $html .= "\t\t\t\t\t</select>";
                    break;

                // textarea
                case 'textarea':
                    $html .= "<textarea name=\"yit_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-$form_name\" rows=\"8\" cols=\"30\" class=\"" . implode( $input_class, ' ' ) . "\" placeholder=\"" . stripslashes_deep( $field['title'], 'highlight-text' ) . "\">$value</textarea>";
                    break;

                // radio
                case 'radio':
                    // options
                    foreach( $field['options'] as $i => $option )
                    {
                        $selected = '';
                        if( isset($field['option_selected']) && $field['option_selected'] == $i )
                            $selected = ' checked=""';

                        $html .= "\t\t\t\t\t\t<input type=\"radio\" name=\"yit_contact[{$field['data_name']}]\" id=\"{$field['data_name']}-$form_name-$i\" value=\"$option\"$selected /><label for=\"{$field['data_name']}-$form_name-$i\">$option</label>\n";
                    }
                    $html .= "\t\t\t\t<div class=\"clear\"></div>\n";
                    break;

                // password
                case 'password':
                    $html .= "<input type=\"password\" name=\"yit_contact[{$field['data_name']}]\" id=\"{$field['data_name']}-$form_name\" class=\"" . implode( $input_class, ' ' ) . "\" value=\"$value\" />";
                    break;

                // file
                case 'file':
                    $html .= "<input type=\"file\" name=\"yit_contact[{$field['data_name']}]\" id=\"{$field['data_name']}-$form_name\" class=\"" . implode( $input_class, ' ' ) . "\" />";
                    break;
            }

            // Icon
            $html .= "</div>";

            // only for clean code
            $html .= "\n";

            $html .= "\t\t\t\t<div class=\"msg-error\">" . $error_msg . "</div><div class=\"clear\"></div>\n";

            $html .= "\t\t\t</li>\n";
        }

        if ( $this->get('enable_captcha' ) == '1') {

            $html .= "<script type=\"text/javascript\">var RecaptchaOptions = {  theme : 'clean'  };</script>";
            $html .= "<li class=\"first-of-line span-12\">";
            $html .= $this->recaptcha( false );
            $html .= "</li><div class=\"clear\"></div>";
        }

        $html .= "\t\t\t<li class=\"submit-button span" . $max_width . "\">\n";
        $html .= "\t\t\t\t<input type=\"text\" name=\"yit_bot\" id=\"yit_bot\" />\n";
        $html .= "\t\t\t\t<input type=\"hidden\" name=\"yit_action\" value=\"sendemail\" id=\"yit_action\" />\n";
        $html .= "\t\t\t\t<input type=\"hidden\" name=\"yit_referer\" value=\"" . yit_curPageURL() . "\" />\n";
        $html .= "\t\t\t\t<input type=\"hidden\" name=\"id_form\" value=\"$this->current_form\" />\n";
        if ( is_shop_installed() && is_product() ) {
            $html .= "\t\t\t\t<input type=\"hidden\" name=\"yit_contact[sku]\" value=\"". $GLOBALS['product']->sku . "\" />";
            $html .= "\t\t\t\t<input type=\"hidden\" name=\"yit_contact[product_id]\" value=\"". $GLOBALS['product']->id . "\" />";
        }
        $html .= "\t\t\t\t<input type=\"submit\" name=\"yit_sendemail\" value=\"" . $this->get('submit_label') . "\" class=\"sendmail " . $this->get('submit_alignment') . "\" />";
        $html .= "\t\t\t\t" . wp_nonce_field( 'yit-sendmail', "_wpnonce", true, false );
        $html .= "\t\t\t\t<div class=\"clear\"></div>";
        $html .= "\t\t\t</li>\n";

        $html .= "\t\t</ul>\n\n";
        $html .= "\t</fieldset>\n";
        //$html .= "<div class=\"general-msg-error\">" . __('* Please fix the errors and send again the message', 'yit') . "</div>";

        $html .= "<div class=\"contact-form-error-messages\">";
        foreach( $js_messages as $id => $msg )
            if(isset($msg) && $msg != '')
                $html .= "<div class=\"contact-form-error-$id contact-form-error\">* $msg</div>\n";
        $html .= "</div>\n";

        $html .= "</form>\n\n";

        $html .= "<div class=\"clear\"></div>";

        /*
        // messages for javascript validation
        $html .= "<script type=\"text/javascript\">\n";
        $html .= "\tvar messages_form_" . $this->current_form . " = {\n";

        foreach( $js_messages as $id => $msg )
            if(isset($msg) && $msg != '')
                $html .= "\t\t$id: \"$msg\",\n";

        // remove last comma
        $html = str_replace( "\t\t$id: \"$msg\",\n", "\t\t$id: \"$msg\"\n", $html );

        $html .= "\t};\n";
        $html .= "</script>";
        */

        $html .= "<script type=\"text/javascript\" src=\"" . get_template_directory_uri() . "/theme/assets/js/contact.js\"></script>";

        if( $echo )
            echo $html;

        return $html;
    }