* @package Core */ if ( ! class_exists( 'FlipperCode_HTML_Markup' ) ) { /** * Generate Bootstrap Form and it's Elements. * * @author Flipper Code * @package Core */ class FlipperCode_HTML_Markup { /** * Form Title * * @var String */ protected $form_title = null; /** * Form Name * * @var String */ public $form_name = null; /** * Form ID * * @var String */ public $form_id = null; /** * Form Action * * @var String */ public $form_class = null; /** * Form Class * * @var String */ public $form_action = ''; /** * Form Orientation - Vertical or Horizontal * * @var String */ public $form_type = 'form-horizontal'; /** * Call to Action Slug * * @var String */ protected $manage_pagename = null; /** * Call to Action Title * * @var String */ protected $manage_pagetitle = null; /** * Success or Failure Form Response * * @var Array */ protected $form_response = null; private static $enable_accordian = false; /** * Form Method - POST or GET * * @var string */ protected $form_method = 'post'; /** * Bootstrap Elements Supported * * @var Array */ private $form_elements = array( 'extensions', 'text', 'checkbox', 'multiple_checkbox', 'checkbox_toggle', 'radio', 'submit', 'button', 'select', 'hidden', 'wp_editor', 'html', 'datalist', 'textarea', 'file', 'div', 'blockquote', 'html', 'image', 'group', 'table', 'message', 'anchor', 'number', 'image_picker', 'radio_slider', 'tab', 'category_selector', 'templates', 'fc_modal', 'select2' ); /** * Attributes Allowed * * @var Array */ private $allowed_attributes; /** * Hidden Fields * * @var Array */ private $form_hiddens = array(); /** * Form nonce key. * * @var string */ private $nonce_key = 'wpgmp-nonce'; /** * Array of Bootstrap Elements * * @var Array */ protected $elements = array(); /** * Array of Previously Stored Elements * * @var Array */ protected $backup_elements = array(); /** * Array of Rendered Elements * * @var Array */ protected $partially_rendered = false; /** * Number of bootstrap columns * * @var Int */ /** * Whether setting api enabled or not. * * @var boolean */ public $setting_api = false; /** * Columns in row. * * @var integer */ protected $columns = 1; /** * Divide Page in multiple parts. * * @var string */ public $spliter = ''; /** * Intialize form properties. */ public function __construct( $options = array() ) { $this->allowed_attributes = array_fill_keys( array( 'min', 'max', 'choose_button', 'remove_button', 'label', 'id', 'class', 'required', 'default_value', 'value', 'options', 'desc', 'before', 'after', 'radio-val-label', 'onclick', 'placeholder', 'textarea_rows', 'textarea_name', 'html', 'current', 'width', 'height', 'src', 'alt', 'heading', 'data', 'show', 'optgroup', 'selectable_optgroup', 'tabs', 'row_class', 'page', 'data_type', 'href', 'target', 'fpc', 'product', 'productTemplate', 'parentTemplate', 'template_list', 'instance', 'dboption', 'template_types', 'templatePath', 'templateURL', 'settingPage', 'customiser', 'attachment_id', 'parent_page_slug', 'data_type', 'fc_modal_header', 'fc_modal_content', 'fc_modal_footer', 'fc_modal_initiator', 'no-sticky', 'customiser', 'customiser_controls', 'data_placeholders', 'display_mode', 'multiple', 'select2', 'tempcol', 'parent_class', 'enable_slider', 'template_custom_html' ), '' ); $this->allowed_attributes['style'] = array(); $this->allowed_attributes['required'] = false; if ( isset( $options ) ) { $this->options = $options; } } /** * Set Form's header * * @param String $form_title Form Title. * @param String $response Success or Failure Message. * @param string $manage_pagetitle Call to Action Title. * @param string $manage_pagename Call to Action Page Slug. */ public function set_header( $form_title, $response, $enable_accordian = '', $manage_pagetitle = '', $manage_pagename = '' ) { if ( isset( $form_title ) && ! empty( $form_title ) ) { $this->form_title = $form_title; } if ( isset( $response ) && ! empty( $response ) ) { $this->form_response = $response; } $this->manage_pagename = $manage_pagename; $this->manage_pagetitle = $manage_pagetitle; self::$enable_accordian = $enable_accordian; } /** * Form Method * * @param string $method Form Method. */ public function set_form_method( $method ) { $this->form_method = $method; } /** * Title Setter * * @param string $title Form Title. */ public function set_title( $title ) { $this->form_title = $title; } /** * Action Setter * * @param String $action Form Action. */ public function set_form_action( $action ) { $this->form_action = $action; } /** * Title Getter * * @return String Get Form Title. */ public function get_title() { if ( isset( $this->form_title ) && ! empty( $this->form_title ) ) { return $this->form_title; } } /** * Call to Action Button */ public static function field_fc_modal( $name, $atts ) { extract( $atts ); $value = isset( $value ) ? $value : $default_value; $id = isset( $id ) ? $id : $name; $fc_modal_header = $fc_modal_header ? $fc_modal_header : ''; $fc_modal_content = $fc_modal_content ? $fc_modal_content : ''; $fc_modal_initiator = $fc_modal_initiator ? $fc_modal_initiator : ''; $modal = '
x

' . $fc_modal_header . '

' . $fc_modal_content . '
'; return $modal; } public static function field_number( $name, $atts ) { $elem_value = ( isset( $atts['value'] ) ) ? $atts['value'] : $atts['default_value']; $min_value = $atts['min'] ? $atts['min'] : 0; $max_value = $atts['max'] ? $atts['max'] : 9999; $element = ''; if ( isset( $atts['desc'] ) && ! empty( $atts['desc'] ) ) { $element .= '

' . $atts['desc'] . '

'; } return apply_filters( 'wpgmp_input_field_' . $name, $element, $name, $atts ); } /** * Get form success or error message. * * @return HTML Success or error message html. */ public function get_form_messages() { if ( empty( $this->form_response ) && ! is_array( $this->form_response ) ) { return; } $response = $this->form_response; $output = ''; if ( isset( $response['error'] ) ) { $output .= '
'; $output .= '' . $response['error'] . '
'; } else { $output .= '
'; $output .= '' . $response['success'] . '
'; } return $output; } /** * Form header getter. * * @return HTML Generate form header html. */ public function show_header() { $output = ''; $output .= '
' . $this->options['productName'] . ' ' . $this->options['productVersion'] . '
'; return $output; } public function product_overview() { if ( ! isset( $this->options['no_header'] ) || $this->options['no_header'] !== true ) { echo wp_kses_post( $this->show_header() ); } $productOverviewObj = new Flippercode_Product_Overview( $this->options ); } public function get_header() { $output = ''; if ( ! isset( $this->options['no_header'] ) || $this->options['no_header'] != true ) { $output = $this->show_header(); } $output .= '
'; $output .= '
' . $this->get_form_messages(); return apply_filters( 'wpgmp_form_header_html', $output ); } /** * Form footer getter. * * @return HTML Generate form footer html. */ public function get_footer() { $output = '
'; return apply_filters( 'wpgmp_form_footer_html', $output ); } /** * Bootstrap columns setter. * * @param int $column Set columns occupied by element. */ public function set_col( $column ) { if ( $this->elements ) { $last_index = key( array_reverse( $this->elements ) ); $this->elements[ $last_index ]['col_after'] = $column; return; } $this->columns = $column ? absint( $column ) : 2; } /** * Bootstrap columns getter. */ public function get_col() { return $this->columns; } /** * Add element in queue. * * @param string $type Element type. * @param string $name Element name. * @param array $args Element Properties. */ public function add_element( $type, $name, $args = array() ) { if ( ! in_array( $type, $this->form_elements ) ) { return; } $this->elements[ $name ] = shortcode_atts( $this->allowed_attributes, $args ); $this->elements[ $name ]['type'] = $type; } public static function apply_extensions( $filter, $value ) { $element_html = ''; $element_html .= apply_filters( $filter, '', $value ); $element_html .= self::field_hidden( 'fc_entity_type', array( 'value' => strtolower( trim( $filter ) ) ) ); return $element_html; } public static function field_extensions( $name, $atts ) { return self::apply_extensions( $name, $atts['value'] ); } /** * Concat form elements together. * * @return html Combined HTML of each elements. */ public function get_combined_markup() { $element_html = ''; if ( $this->elements ) { $elements = $this->elements; $num = 0; $tmpl = false; $section_start = ''; while ( $num < count( $elements ) ) { $col = $this->get_col(); $elem_content = ''; foreach ( array_slice( $elements, $num, $col ) as $name => $atts ) { if ( self::$enable_accordian == true ) { if ( $atts['type'] == 'group' ) { $before = apply_filters( 'wpgmp_element_before_start_row', '
' ); $after = apply_filters( 'wpgmp_element_after_end_row', '
' ); $group_section_start = '
'; } elseif ( $atts['type'] == 'templates' ) { $group_section_start = ''; // Do Noting For Now } elseif ( $atts['type'] == 'hidden' ) { $before = ''; $after = ''; $group_section_start = ''; } elseif ( $atts['type'] == 'submit' ) { $before = apply_filters( 'wpgmp_element_before_start_row', '
' ); $after = apply_filters( 'wpgmp_element_after_end_row', '
' ); $group_section_start = ''; } else { $before = apply_filters( 'wpgmp_element_before_start_row', '
' ); $after = apply_filters( 'wpgmp_element_after_end_row', '
' ); $group_section_start = ''; } } else { if ( $atts['type'] == 'hidden' ) { $before = ''; $after = ''; $group_section_start = ''; } else { $group_section_start = ''; $before = apply_filters( 'wpgmp_element_before_start_row', '
' ); $after = apply_filters( 'wpgmp_element_after_end_row', '
' ); } } $row_extra = false; $temp = $before; if ( ! isset( $atts['type'] ) || ! is_string( $name ) ) { continue; } if ( 'hidden' == $atts['type'] ) { $before = ''; $after = ''; $elem_content .= call_user_func( 'FlipperCode_HTML_Markup::field_' . $atts['type'], $name, $atts ); continue; } if ( 'templates' == $atts['type'] ) { $before = ''; $after = ''; $elem_content .= call_user_func( 'FlipperCode_HTML_Markup::field_' . $atts['type'], $name, $atts ); continue; } $elem_content .= $this->get_element_html( $name, $atts['type'], $atts ); if ( isset( $atts['col_after'] ) ) { $this->columns = $atts['col_after']; } if ( isset( $atts['show'] ) and 'false' == $atts['show'] ) { $row_extra = true; } } if ( true == $row_extra ) { $temp = str_replace( '{modifier}', 'hiderow', $temp ); } else { $temp = str_replace( '{modifier}', '', $temp ); } if ( ! empty( $elem_content ) ) { $element_html .= $temp . $elem_content . $after . $group_section_start; } $num = $num + $col; } } return $element_html; } /** * Form header getter. * * @return html Generate form header html. */ public function get_form_header() { $form_header = '
form_name ) && ! empty( $this->form_name ) ) { $form_header .= ' name="' . esc_attr( $this->form_name ) . '" '; } if ( isset( $this->form_id ) && ! empty( $this->form_id ) ) { $form_header .= ' id="' . esc_attr( $this->form_id ) . '" '; } if ( isset( $this->form_class ) && ! empty( $this->form_class ) ) { $form_header .= ' class="' . esc_attr( $this->form_class ) . '" '; } $form_header .= '>'; $form_header .= '
'; if ( self::$enable_accordian == true ) { $form_header .= '
'; } return $form_header; } /** * Form nonce key setter. * * @param string $nonce_key Form nonce key. */ public function set_form_nonce( $nonce_key ) { $this->nonce_key = $nonce_key; } /** * Form footer getter. * * @return html Generate form footer html. */ public function get_form_footer() { if ( self::$enable_accordian == true ) { $form_footer = '
'; } else { $form_footer = ''; } $form_footer .= wp_nonce_field( $this->nonce_key, '_wpnonce', true, false ); $form_footer .= '
'; return $form_footer; } /** * Echo or return html elements. * * @param boolean $echo True to display. * @return html html Generate form html */ public function render( $echo = true ) { if ( ! $this->elements || ! is_array( $this->elements ) and $this->partially_rendered == false ) { echo '

Please add form element first.

'; return; } $form_output = ''; if ( empty( $this->backup_elements ) and ! isset( $this->options['ajax'] ) and ! isset( $this->options['elements_only'] ) ) { $form_output = $this->get_header(); } if ( empty( $this->backup_elements ) and ! isset( $this->options['elements_only'] ) ) { $form_header = $this->get_form_header(); } if ( isset( $this->options['elements_only'] ) ) { $form_html = $this->get_combined_markup(); } else { $form_html = $form_header . $this->get_combined_markup() . $this->get_form_footer(); } if ( isset( $this->spliter ) and $this->spliter != '' ) { $spliter = str_replace( '%form', $form_html, $this->spliter ); } else { $spliter = $form_html; } $form_output .= $spliter; if ( ! isset( $this->options['ajax'] ) and ! isset( $this->options['elements_only'] ) ) { $form_output .= $this->get_footer(); } if ( $echo ) { $form_output = balanceTags( $form_output ); echo $form_output; } else { return $form_output; } } /** * Element's html creater. * * @param string $name Element Name. * @param string $type Element Type. * @param array $atts Element Options. * @return html Element's Html. */ public static function get_element_html( $name, $type, $atts ) { $element_output = ''; if ( 'hidden' == $type ) { $element_output = call_user_func( 'FlipperCode_HTML_Markup::field_' . $type, $name, $atts ); return $element_output; } elseif ( 'templates' == $type ) { $element_output = call_user_func( 'FlipperCode_HTML_Markup::field_' . $type, $name, $atts ); return $element_output; } else { if ( ! empty( $atts['label'] ) ) { $element_output .= apply_filters( 'wpgmp_input_label_' . $name, '
' ) . ''; } $element_output .= ( isset( $atts['before'] ) && ! empty( $atts['before'] ) ) ? $atts['before'] : '
'; $element_output .= call_user_func( 'FlipperCode_HTML_Markup::field_' . $type, $name, $atts ); $element_output .= ( isset( $atts['after'] ) && ! empty( $atts['after'] ) ) ? $atts['after'] : '
'; return $element_output; } } /** * Display mandatory indicator on element. * * @param boolean $required Whether field is required or not. * @return html Mandatory indicator. */ public static function element_mandatory( $required = false ) { if ( true == $required ) { return '*'; } } /** * Attributes Generator for the element. * * @param array $atts Attributes keys and values. * @return string Attributes section of the element. */ protected static function get_element_attributes( $atts ) { if ( ! is_array( $atts ) ) { return null; } $attributes = array(); if ( isset( $atts['id'] ) && ! empty( $atts['id'] ) ) { $attributes[] = 'id="' . $atts['id'] . '"'; } $classes = ( ! empty( $atts['class'] ) ) ? $atts['class'] : 'form-control'; if ( isset( $atts['type'] ) && $atts['type'] == 'submit' ) { $classes .= ' fc-btn fc-btn-submit fc-btn-big'; } $attributes[] = 'class="' . $classes . '"'; if ( isset( $atts['style'] ) && ! empty( $atts['style'] ) ) { $style = 'style="'; foreach ( $atts['style'] as $key => $value ) { $style .= $key . ':' . $value . ';'; } $style .= '"'; $attributes[2] = $style; } if ( isset( $atts['placeholder'] ) && ! empty( $atts['placeholder'] ) ) { $attributes[] = 'placeholder="' . esc_attr( $atts['placeholder'] ) . '"'; } if ( isset( $atts['data'] ) && ! empty( $atts['data'] ) ) { foreach ( $atts['data'] as $key => $value ) { if ( ! is_array( $value ) ) { $attributes[] = 'data-' . $key . '="' . esc_attr( $value ) . '"'; } } } if ( isset( $atts['src'] ) && ! empty( $atts['src'] ) ) { $attributes[] = 'src="' . esc_url( $atts['src'] ) . '"'; } if ( isset( $atts['alt'] ) && ! empty( $atts['alt'] ) ) { $attributes[] = 'alt="' . esc_attr( $atts['alt'] ) . '"'; } if ( isset( $atts['height'] ) && ! empty( $atts['height'] ) ) { $attributes[] = 'height="' . esc_attr( $atts['height'] ) . '"'; } if ( isset( $atts['width'] ) && ! empty( $atts['width'] ) ) { $attributes[] = 'width="' . esc_attr( $atts['width'] ) . '"'; } if ( isset( $atts['value'] ) && ! empty( $atts['value'] ) and ! is_array( $atts['value'] ) ) { $attributes[] = 'value="' . esc_attr( $atts['value'] ) . '"'; } if ( isset( $atts['name'] ) && ! empty( $atts['name'] ) ) { $attributes[] = 'name="' . esc_attr( $atts['name'] ) . '"'; } if ( ! $attributes ) { return null; } return implode( ' ', $attributes ); } public static function get_all_templates_with_slider( $name, $atts, $accordian ) { $templateCategories = $atts['template_types']; $templatePath = $atts['templatePath']; $templateURL = $atts['templateURL']; $settingPage = $atts['settingPage']; $customiser = $atts['customiser']; $dbsetting = get_option( $atts['dboption'] ); if ( ! is_array( $dbsetting ) ) { $dbsetting = unserialize( $dbsetting ); } if ( ! isset( $customiser ) ) { $custmiserDisabled = false; } elseif ( isset( $customiser ) and $customiser == 'false' ) { $custmiserDisabled = true; } else { $custmiserDisabled = false; } $html = ''; foreach ( $templateCategories as $templateType ) { if ( $accordian == true ) { $html .= '
'; $html .= self::get_element_html( $templateType . '_group', 'group', array( 'value' => $atts['label'], 'before' => '
', 'after' => '
', 'for_template' => 'yes', ) ); $html .= '
'; } else { $html .= self::get_element_html( $templateType . '_group', 'group', array( 'value' => $atts['label'], 'before' => '
', 'after' => '
', 'for_template' => 'yes', ) ); } $directories = glob( $templatePath . $templateType . '/*', GLOB_ONLYDIR ); if ( $accordian == true ) { $html .= '
'; } if ( ! empty( $atts['template_custom_html'] ) && is_array( $atts['template_custom_html'] ) && $atts['template_custom_html']['position'] == 'top' ) { $html .= isset( $atts['template_custom_html']['custom_html'] ) && ! empty( $atts['template_custom_html']['custom_html'] ) ? $atts['template_custom_html']['custom_html'] : ''; } $html .= "
"; $uploads = wp_upload_dir(); $product = $atts['instance']; $for = $atts['template_types'][0]; $path = $uploads['basedir'] . '/' . $product . '/' . $for; $uploadsurl = $uploads['baseurl'] . '/' . $product . '/' . $for; $fromUploads = glob( $path . '/*', GLOB_ONLYDIR ); if ( is_array( $fromUploads ) ) { $directories = array_merge( $directories, $fromUploads ); } foreach ( $directories as $key => $directory ) { $parentTemplate = $directory = basename( $directory ); if ( file_exists( $templatePath . $templateType . '/' . $directory . '/' . $directory . '.png' ) ) { $preview = $templateURL . $templateType . '/' . $directory . '/' . $directory . '.png'; } else { $preview = $uploadsurl . '/' . $directory . '/' . $directory . '.png'; } $title = ucwords( $directory ); $atts['productTemplate'] = $directory; $atts['templatetype'] = $templateType; $atts['settingPage'] = $settingPage; $customiserLink = self::get_product_customizer_link( $atts ); $html .= '
'; if ( isset( $atts['current'] ) && ! empty( $atts['current'] ) ) { $currentTemplateCondition = ( $directory == $atts['current'] ) ? true : false; } else { $currentTemplateCondition = ( isset( $dbsetting['default_templates'][ $templateType ] ) && $dbsetting['default_templates'][ $templateType ] != $directory ) ? true : false; } // echo $directory.'Test -'.$atts['current']; $user_uploaded_template = array_filter( $fromUploads, function( $var ) use ( $directory ) { return strpos( $var, $directory ) !== false; } ); $type = ( ! empty( $user_uploaded_template ) ) ? 'user-temp' : 'static-temp'; $useThis = ( $currentTemplateCondition && ! empty( $atts['current'] ) ) ? "" : ""; $deleteThis = ''; if ( ! empty( $user_uploaded_template ) ) { $deleteThis = ( $currentTemplateCondition ) ? "" : ''; } if ( ! $custmiserDisabled ) { $fctools = "
" . $useThis . " | Customize
"; } else { $fctools = "
'; } if ( isset( $atts['template_list'] ) && ! empty( $atts['template_list'] ) ) { $title = $atts['template_list'][ $directory ]; } $html .= "
" . ucwords( $title ) . '
' . $fctools . '
'; } $html .= '
'; if ( ! $custmiserDisabled ) { $html .= "
"; $html .= self::get_userdefined_templates( $name, $atts, $templateType, $parentTemplate ); $html .= '
'; } if ( ! empty( $atts['template_custom_html'] ) && is_array( $atts['template_custom_html'] ) && $atts['template_custom_html']['position'] == 'bottom' ) { $html .= isset( $atts['template_custom_html']['custom_html'] ) && ! empty( $atts['template_custom_html']['custom_html'] ) ? $atts['template_custom_html']['custom_html'] : ''; } if ( $accordian == true ) { $html .= '
'; } } return $html; } public static function get_all_templates( $name, $atts, $accordian ) { $templateCategories = $atts['template_types']; $templatePath = $atts['templatePath']; $templateURL = $atts['templateURL']; $settingPage = $atts['settingPage']; $customiser = $atts['customiser']; $dbsetting = get_option( $atts['dboption'] ); if ( ! is_array( $dbsetting ) ) { $dbsetting = unserialize( $dbsetting ); } if ( ! isset( $customiser ) ) { $custmiserDisabled = false; } elseif ( isset( $customiser ) and $customiser == 'false' ) { $custmiserDisabled = true; } else { $custmiserDisabled = false; } $html = ''; foreach ( $templateCategories as $templateType ) { if ( $accordian == true ) { $html .= '
'; $html .= self::get_element_html( $templateType . '_group', 'group', array( 'value' => $atts['label'], 'before' => '
', 'after' => '
', 'for_template' => 'yes', ) ); $html .= '
'; } else { $html .= self::get_element_html( $templateType . '_group', 'group', array( 'value' => $atts['label'], 'before' => '
', 'after' => '
', 'for_template' => 'yes', ) ); } $directories = glob( $templatePath . $templateType . '/*', GLOB_ONLYDIR ); if ( $accordian == true ) { $html .= '
'; } if ( ! empty( $atts['template_custom_html'] ) && is_array( $atts['template_custom_html'] ) && $atts['template_custom_html']['position'] == 'top' ) { $html .= isset( $atts['template_custom_html']['custom_html'] ) && ! empty( $atts['template_custom_html']['custom_html'] ) ? $atts['template_custom_html']['custom_html'] : ''; } $html .= "
"; $uploads = wp_upload_dir(); $product = $atts['instance']; $for = $atts['template_types'][0]; $path = $uploads['basedir'] . '/' . $product . '/' . $for; $uploadsurl = $uploads['baseurl'] . '/' . $product . '/' . $for; $fromUploads = glob( $path . '/*', GLOB_ONLYDIR ); if ( is_array( $fromUploads ) ) { $directories = array_merge( $directories, $fromUploads ); } foreach ( $directories as $key => $directory ) { $parentTemplate = $directory = basename( $directory ); if ( file_exists( $templatePath . $templateType . '/' . $directory . '/' . $directory . '.png' ) ) { $preview = $templateURL . $templateType . '/' . $directory . '/' . $directory . '.png'; } else { $preview = $uploadsurl . '/' . $directory . '/' . $directory . '.png'; } $title = ucwords( $directory ); $atts['productTemplate'] = $directory; $atts['templatetype'] = $templateType; $atts['settingPage'] = $settingPage; $customiserLink = self::get_product_customizer_link( $atts ); if ( ! isset( $atts['tempcol'] ) || empty( $atts['tempcol'] ) ) { if ( $key != 0 && $key % 3 == 0 ) { $html .= '
'; } } else { $break_on = 12 / $atts['tempcol']; if ( $key != 0 && $key % $break_on == 0 ) { $html .= '
'; } } $currentTemplateCondition = ( isset( $dbsetting['default_templates'][ $templateType ] ) && $dbsetting['default_templates'][ $templateType ] != $directory ) ? true : false; $user_uploaded_template = array_filter( $fromUploads, function( $var ) use ( $directory ) { return strpos( $var, $directory ) !== false; } ); $type = ( ! empty( $user_uploaded_template ) ) ? 'user-temp' : 'static-temp'; $useThis = ( $currentTemplateCondition ) ? "" : ""; $deleteThis = ''; if ( ! empty( $user_uploaded_template ) ) { $deleteThis = ( $currentTemplateCondition ) ? "
  • " : ''; } if ( ! $custmiserDisabled ) { $fctools = "
    " . $useThis . " | Customize
    "; } else { $fctools = "
    '; } $tempcol = ( isset( $atts['tempcol'] ) && ! empty( $atts['tempcol'] ) ) ? $atts['tempcol'] : '4'; if ( isset( $atts['template_list'] ) && ! empty( $atts['template_list'] ) ) { $title = $atts['template_list'][ $directory ]; } $html .= "
    " . ucwords( $title ) . '
    ' . $fctools . '
    '; } $html .= '
    '; if ( ! $custmiserDisabled ) { $html .= "
    "; $html .= self::get_userdefined_templates( $name, $atts, $templateType, $parentTemplate ); $html .= '
    '; } if ( ! empty( $atts['template_custom_html'] ) && is_array( $atts['template_custom_html'] ) && $atts['template_custom_html']['position'] == 'bottom' ) { $html .= isset( $atts['template_custom_html']['custom_html'] ) && ! empty( $atts['template_custom_html']['custom_html'] ) ? $atts['template_custom_html']['custom_html'] : ''; } if ( $accordian == true ) { $html .= '
    '; } } return $html; } /** * Image picker element. * * @param string $name No use. * @param array $atts Attributes for custom html. * @return html Image Picker. */ function get_css_property_unit( $property ) { switch ( $property ) { case 'width': $unit = '%'; break; case 'font-size': $unit = 'px'; break; case 'border-radius': $unit = 'px'; case 'padding': $unit = 'px'; case 'padding-top': $unit = 'px'; case 'padding-right': $unit = 'px'; case 'padding-bottom': $unit = 'px'; case 'padding-left': $unit = 'px'; case 'margin': $unit = 'px'; case 'margin-top': $unit = 'px'; case 'margin-right': $unit = 'px'; case 'margin-bottom': $unit = 'px'; case 'margin-left': $unit = 'px'; break; default: $unit = ''; } return $unit; } function generate_css( $prefix, $originalelements, $realformelements, $isImportant ) { $prefixspecificstyle = ''; $final = array(); $important = ( $isImportant ) ? '!important' : ''; if ( is_array( $originalelements ) ) { foreach ( $originalelements as $element ) { foreach ( $realformelements as $key => $value ) { if ( strpos( $key, $element ) === 0 ) { $property = explode( '*', $key ); $final[ $element ][ $property[1] ] = $value; } } } foreach ( $final as $selector => $cssInfo ) { $prefixspecificstyle .= $prefix . ' .' . $selector . '{ '; foreach ( $cssInfo as $cssproperty => $csspropertyvalue ) { $unit = self::get_css_property_unit( $cssproperty ); $unit = ''; $prefixspecificstyle .= $cssproperty . ' : ' . $csspropertyvalue . $unit . $important . '; '; } $prefixspecificstyle .= ' }'; } } return $prefixspecificstyle; } function give_css_with_prefix( $prefix, $layoutid, $productcustomiserdata ) { $originalelements = $productcustomiserdata[ $layoutid ]['originalelements']; $realformelements = $productcustomiserdata[ $layoutid ]['formdata']; $backupStyle = self::generate_css( $prefix, $originalelements, $realformelements, false ); return $backupStyle; } public static function get_userdefined_templates( $name, $atts, $templateType, $parentTemplate ) { $dbsetting = get_option( $atts['dboption'] ); $userdefinetemplates = get_option( $atts['dboption'] . '-fc-styles' ); $templatetype = $atts['templatetype']; foreach ( $userdefinetemplates as $key => $templates ) { if ( $templates['templateType'] != $templatetype ) { continue; } $directory = $key; $templatePreviewSpecificClass = '.current-templte-' . $directory; $css = self::give_css_with_prefix( $templatePreviewSpecificClass, $directory, $userdefinetemplates ); $preview = html_entity_decode( $templates['templateMarkup'] ); $title = ucwords( $directory ); $atts['productTemplate'] = $directory; $atts['templatetype'] = $templates['templateType']; $atts['parentTemplate'] = $parentTemplate; $customiserLink = self::get_product_customizer_link( $atts ); if ( $key % 3 == 0 and $key != 0 ) { $html .= '
    '; } $html .= "
    "; $currentTemplateCondition = ( $dbsetting['default_templates'][ $templateType ] != $key ) ? true : false; $useThis = ( $currentTemplateCondition ) ? "Use this" : "In Use"; $deleteTemplateLink = ( $currentTemplateCondition ) ? "Delete This Template" : ''; $html .= "
    " . $preview . "
    " . $title . " - Custom Defined Template
    " . $useThis . " | Customize | " . $deleteTemplateLink . '
    '; } return $html; } public static function get_product_customizer_link( $linkInfo ) { $info = array( 'fpc' => 'true', 'product' => $linkInfo['product'], 'productTemplate' => $linkInfo['productTemplate'], 'instance' => $linkInfo['instance'], 'templatetype' => $linkInfo['templatetype'], 'settingPage' => $linkInfo['settingPage'], ); if ( ! empty( $linkInfo['parentTemplate'] ) ) { $info['parentTemplate'] = $linkInfo['parentTemplate']; } $productCustomizerLink = add_query_arg( $info, admin_url( '?page=flippercode-product-customiser' ) ); return $productCustomizerLink; } public static function field_templates( $name, $atts ) { $accordian = self::$enable_accordian; $templatesHtml = ''; if ( isset( $atts['enable_slider'] ) && ! empty( $atts['enable_slider'] ) && $atts['enable_slider'] == true ) { $templatesHtml .= self::get_all_templates_with_slider( $name, $atts, $accordian ); } else { $templatesHtml .= self::get_all_templates( $name, $atts, $accordian ); } return $templatesHtml; } /** * Image picker element. * * @param string $name No use. * @param array $atts Attributes for custom html. * @return html Image Picker. */ public static function field_image_picker( $name, $atts ) { $display = ( ! empty( $atts['src'] ) ) ? 'block' : 'none'; $imageClass = ( empty( $atts['src'] ) ) ? 'noimage' : ''; $html = self::field_image( 'selected_image', array( 'src' => $atts['src'], 'width' => '100', 'class' => $imageClass . ' selected_image', 'height' => '100', 'required' => $atts['required'], 'style' => array( 'display' => $display, 'float' => 'right', ), ) ); $html .= self::field_anchor( 'choose_image', array( 'value' => $atts['choose_button'], 'href' => 'javascript:void(0);', 'class' => 'fc-btn fc-btn-blue btn-small choose_image fc-3 ' . $atts['class'] . '', 'data' => array( 'target' => $name ), 'id' => $atts['id'] . '_link', ) ); $html .= self::field_anchor( 'remove_image', array( 'value' => $atts['remove_button'], 'before' => '
    ', 'after' => '
    ', 'href' => 'javascript:void(0);', 'class' => 'fc-btn fc-btn-red btn-small remove_image fc-3 fc-offset-1', 'data' => array( 'target' => $name ), 'style' => array( 'display' => $display ), ) ); $html .= self::field_hidden( 'group_marker', array( 'value' => $atts['src'], 'id' => $name, 'name' => $name, ) ); $html .= self::field_hidden( $name . '_attachment_id', array( 'value' => $atts['attachment_id'], 'id' => $name . '_attachment_id', ) ); if ( isset( $atts['desc'] ) && ! empty( $atts['desc'] ) ) { $html .= '

    ' . $atts['desc'] . '

    '; } return $html; } /** * Custom HTML to display. * * @param string $name No use. * @param array $atts Attributes for custom html. * @return html Body of custom html. */ public static function field_html( $name, $atts ) { extract( $atts ); return '
    ' . $html . '
    '; } /** * Radio Slider * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_radio_slider( $name, $atts ) { extract( $atts ); $value = $value ? $value : $default_value; $min = $min ? $min : 1; $max = $max ? $max : 100; $html = '
    '; if ( isset( $atts['desc'] ) && ! empty( $atts['desc'] ) ) { $html .= '

    ' . $atts['desc'] . '

    '; } return $html; } /** * Hidden Field * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_hidden( $name, $atts ) { extract( $atts ); if ( ! isset( $default_value ) ) { $default_value = ''; } if ( ! isset( $id ) ) { $id = $name; } $value = $value ? $value : $default_value; return ''; } /** * Group Heading * * @param string $name Group title. * @param array $atts Attributes. * @return html Element Html. */ public static function field_group( $name, $atts ) { extract( $atts ); if ( ! isset( $atts['class'] ) ) { $atts['class'] = ''; } $atts['class'] = 'fc-title-blue group-element' . $atts['class']; if ( isset( $atts['default_value'] ) ) { $default_value = $atts['default_value']; } else { $default_value = ''; } $value = $value ? ucwords( $value ) : ucwords( $default_value ); return '

    ' . $value . '

    '; } /** * DIV node * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_div( $name, $atts ) { extract( $atts ); $value = $value ? $value : $default_value; return '
    ' . $value . '
    '; } /** * Blockquote node * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_blockquote( $name, $atts ) { extract( $atts ); $value = $value ? $value : $default_value; return '
    ' . $atts['value'] . '
    '; } /** * Text Input element. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_text( $name, $atts ) { $elem_value = ( isset( $atts['value'] ) ) ? $atts['value'] : $atts['default_value']; if ( isset( $atts['class'] ) && strstr( $atts['class'], 'color' ) !== false ) { if ( $atts['value'] == '#' || empty( $atts['value'] ) ) { $elem_value = ( isset( $atts['default_value'] ) ) ? $atts['default_value'] : ''; } $elem_value = str_replace( '#', '', $elem_value ); $elem_value = '#' . $elem_value; } $element = ''; if ( isset( $atts['desc'] ) && ! empty( $atts['desc'] ) ) { $element .= '

    ' . $atts['desc'] . '

    '; } return apply_filters( 'wpgmp_input_field_' . $name, $element, $name, $atts ); } /** * Display Information message in

    tag. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_infoarea( $name, $atts ) { return '

    ' . $atts['desc'] . '

    '; } /** * Image tag. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_image( $name, $atts ) { if ( isset( $atts['show'] ) and $atts['show'] == 'false' ) { $hide = 'display:none;'; } else { $hide = ''; } if ( ! isset( $atts['alt'] ) ) { $atts['alt'] = ''; } $element = '' . $atts['alt'] . ''; if ( isset( $atts['desc'] ) && ! empty( $atts['desc'] ) ) { $element .= '

    ' . $atts['desc'] . '

    '; } return apply_filters( 'wpgmp_input_field_' . $name, $element, $name, $atts ); } /** * Generate output using wp_editor. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_wp_editor( $name, $atts ) { $value = $atts['value'] ? $atts['value'] : $atts['default_value']; $args = array( 'textarea_rows' => $atts['textarea_rows'], 'textarea_name' => $atts['textarea_name'], 'editor_class' => $atts['class'], ); $output = ''; ob_start(); wp_editor( esc_textarea( $value ), $name, $args ); $output .= ob_get_contents(); ob_clean(); $output .= '

    ' . $atts['desc'] . '

    '; return $output; } /** * Textarea element. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_textarea( $name, $atts ) { $default_value = isset( $atts['default_value'] ) ? $atts['default_value'] : ''; $elem_value = $atts['value'] ? $atts['value'] : $default_value; $element = ''; if ( isset( $atts['desc'] ) && ! empty( $atts['desc'] ) ) { $element .= '

    ' . $atts['desc'] . '

    '; } return apply_filters( 'wpgmp_input_field_' . $name, $element, $name, $atts ); } /** * File Input element. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_file( $name, $atts ) { $elem_value = $atts['value'] ? $atts['value'] : $atts['default_value']; $element = '
    '; if ( isset( $atts['desc'] ) && ! empty( $atts['desc'] ) ) { $element .= '

    ' . $atts['desc'] . '

    '; } return apply_filters( 'wpgmp_input_field_' . $name, $element, $name, $atts ); } /** * Select Input element. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_select( $name, $atts ) { if ( ! isset( $atts['options'] ) || empty( $atts['options'] ) ) { return; } $options = ''; $defaul_val = isset( $atts['default_value'] ) ? $atts['default_value'] : ''; $elem_value = isset( $atts['current'] ) ? $atts['current'] : $defaul_val; $optgroup = isset( $atts['optgroup'] ) ? $atts['optgroup'] : 'false'; $selectable_optgroup = isset( $atts['selectable_optgroup'] ) ? $atts['selectable_optgroup'] : 'false'; $placeholder = isset( $atts['placeholder'] ) ? $atts['placeholder'] : ''; $id = ( isset( $atts['id'] ) && ( $atts['id'] != '' ) ) ? $atts['id'] : $name; $main_class = ( isset( $atts['class'] ) ) ? $atts['class'] : ''; if ( 'true' == $optgroup ) { if ( 'true' == $selectable_optgroup ) { foreach ( $atts['options'] as $opt_name => $values ) { foreach ( $values as $key => $value ) { if ( $value == $opt_name ) { $class = 'optionParent'; } else { $class = 'optionChild'; } $options .= ''; } } } else { foreach ( $atts['options'] as $opt_name => $values ) { $options .= ''; foreach ( $values as $key => $value ) { $options .= ''; } $options .= ''; } } } else { foreach ( $atts['options'] as $key => $value ) { $options .= ''; } } $main_class = ( isset( $atts['select2'] ) && ( $atts['select2'] == 'false' ) ) ? 'class="form-control ' . $main_class . '"' : 'class="fc_select2 form-control ' . $main_class . '"'; $element = ''; if ( isset( $atts['desc'] ) && ! empty( $atts['desc'] ) ) { $element .= '

    ' . $atts['desc'] . '

    '; } return apply_filters( 'wpgmp_select_field_' . $name, $element, $name, $atts ); } /** * Submit button element. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_submit( $name, $atts ) { if ( isset( $atts['no-sticky'] ) and $atts['no-sticky'] == 'true' ) { $no_sticky = 'fc-no-sticky'; } else { $no_sticky = ''; } $element = ''; return apply_filters( 'wpgmp_input_field_' . $name, $element, $name, $atts ); } /** * Button element. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_button( $name, $atts ) { $eventstr = ''; if ( isset( $atts['onclick'] ) and ! empty( $atts['onclick'] ) ) { $eventstr .= 'onclick =' . stripcslashes( $atts['onclick'] ); } $element = ''; if ( isset( $atts['desc'] ) && ! empty( $atts['desc'] ) ) { $element .= '

    ' . $atts['desc'] . '

    '; } return apply_filters( 'wpgmp_input_field_' . $name, $element, $name, $atts ); } /** * Checkbox input element. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_checkbox( $name, $atts ) { $id = ( ! empty( $atts['id'] ) ) ? $atts['id'] : $name; $display_mode = ( ! empty( $atts['display_mode'] ) ) ? $atts['display_mode'] : ''; $value = $atts['value'] ? $atts['value'] : $atts['default_value']; $desc = ''; if ( isset( $atts['desc'] ) ) { $desc = $atts['desc']; } $element = ' '; return apply_filters( 'wpgmp_input_field_' . $name, $element, $name, $atts ); } /** * Switch input element. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_checkbox_toggle( $name, $atts ) { $atts['id'] = ( ! empty( $atts['id'] ) ) ? $atts['id'] : ''; $display_mode = ( ! empty( $atts['display_mode'] ) ) ? $atts['display_mode'] : ''; $value = $atts['value'] ? $atts['value'] : $atts['default_value']; $element = ' '; if ( isset( $atts['desc'] ) && ! empty( $atts['desc'] ) ) { $element .= '

    ' . $atts['desc'] . '

    '; } return apply_filters( 'wpgmp_input_field_' . $name, $element, $name, $atts ); } /** * Multiple Checkbox input element. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_multiple_checkbox( $name, $atts ) { $id = ( ! empty( $atts['id'] ) ) ? $atts['id'] : $name; $value = $atts['value'] ? $atts['value'] : $atts['default_value']; $element = ''; $display_mode = ( ! empty( $atts['display_mode'] ) ) ? $atts['display_mode'] : ''; if ( is_array( $value ) ) { foreach ( $value as $key => $val ) { if ( is_array( $atts['current'] ) and in_array( $key, $atts['current'] ) ) { $element .= ' '; } else { $element .= ' '; } } } return apply_filters( 'wpgmp_input_field_' . $name, $element, $name, $atts ); } /** * Anchor tag element. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_anchor( $name, $atts ) { $style = ( isset( $atts['show'] ) and $atts['show'] == 'false' ) ? "style='display:none;'" : ''; $id = ( ! empty( $atts['id'] ) ) ? $atts['id'] : $name; $value = $atts['value'] ? $atts['value'] : $atts['default_value']; if ( ! isset( $atts['target'] ) ) { $atts['target'] = ''; } if ( ! isset( $atts['id'] ) ) { $atts['id'] = $name; } $element = '' . $value . ''; if ( isset( $atts['desc'] ) && ! empty( $atts['desc'] ) ) { $element .= '

    ' . $atts['desc'] . '

    '; } return apply_filters( 'wpgmp_input_field_' . $name, $element, $name, $atts ); } /** * Radio input element. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_radio( $name, $atts ) { if ( ! isset( $atts['default_value'] ) ) { $atts['default_value'] = ''; } $elem_value = $atts['current'] ? $atts['current'] : $atts['default_value']; $element = ''; $radio_options = $atts['radio-val-label']; if ( is_array( $atts['radio-val-label'] ) ) { $display_mode = ( ! empty( $atts['display_mode'] ) ) ? $atts['display_mode'] : ''; foreach ( $radio_options as $radio_val => $radio_label ) { $element .= ''; } } if ( isset( $atts['desc'] ) && ! empty( $atts['desc'] ) ) { $element .= '

    ' . $atts['desc'] . '

    '; } return apply_filters( 'wpgmp_input_field_' . $name, $element, $name, $atts ); } /** * Message boxes. * * @param string $name Element name. * @param array $atts Attributes. * @return html Element Html. */ public static function field_message( $name, $atts ) { $id = isset( $atts['id'] ) ? $atts['id'] : ''; $element = '
    ' . $atts['value'] . '
    '; return apply_filters( 'wpgmp_input_field_' . $name, $element, $name, $atts ); } /** * Sub heading * * @param string $heading heading. * @return html blockquote html wrapper. */ public static function sub_heading( $heading ) { return '
    ' . $heading . '
    '; } public static function field_tab( $name, $atts ) { $tabs = $atts['tabs']; $current = $atts['current']; $page = $atts['page']; $parent_page_slug = $atts['parent_page_slug']; if ( ! empty( $parent_page_slug ) and $parent_page_slug = 'page' ) { $pageslug = 'edit.php?post_type=page&page='; } else { $pageslug = '?page='; } $element = '