<?php
/* ==========================================================
  Contact form 7
=========================================================== */
if ( !function_exists('confin_contact7_function')) {
  function confin_contact7_function( $atts, $content = NULL ) {
    extract($atts);

      $e_uniqid       = uniqid();
      $inline_style   = '';

      if ( $title_size || $title_color  ) {
        $inline_style .= '.contact-pg-section-'.$e_uniqid .'.contact-pg-section .section-title h2 {';
        $inline_style .= ( $title_size ) ? 'font-size:'.confin_core_check_px($title_size) .';' : '';
        $inline_style .= ( $title_color ) ? 'color:'. $title_color .';' : '';
        $inline_style .= '}';
      }
      if ( $subtitle_size || $subtitle_color  ) {
        $inline_style .= '.contact-pg-section-'.$e_uniqid .'.contact-pg-section .section-title span {';
        $inline_style .= ( $subtitle_size ) ? 'font-size:'.confin_core_check_px($subtitle_size) .';' : '';
        $inline_style .= ( $subtitle_color ) ? 'color:'. $subtitle_color .';' : '';
        $inline_style .= '}';
      }
      if ( $desc_size || $desc_color  ) {
        $inline_style .= '.contact-pg-section-'.$e_uniqid .'.contact-pg-section .section-title + p {';
        $inline_style .= ( $desc_size ) ? 'font-size:'.confin_core_check_px($desc_size) .';' : '';
        $inline_style .= ( $desc_color ) ? 'color:'. $desc_color .';' : '';
        $inline_style .= '}';
      }

      if ( $button_color ) {
        $inline_style .= '.contact-pg-section-'.$e_uniqid .'.contact-pg-section .contact-form-area form input[type=submit], .contact-pg-section-'.$e_uniqid .'.contact-section .contact-form-area form input[type=submit] {';
        $inline_style .= ( $button_color ) ? 'color:'. $button_color .';' : '';
        $inline_style .= '}';
      }
      if ( $border_color ) {
        $inline_style .= '.contact-pg-section-'.$e_uniqid .'.contact-pg-section .contact-form-area form input[type=submit], .contact-pg-section-'.$e_uniqid .'.contact-section .contact-form-area form input[type=submit] {';
        $inline_style .= ( $border_color ) ? 'border-color:'. $border_color .';' : '';
        $inline_style .= '}';
      }
      if ( $button_hover ) {
        $inline_style .= '.contact-pg-section-'.$e_uniqid .'.contact-pg-section .contact-form-area form input[type=submit]:hover, .contact-pg-section-'.$e_uniqid .'.contact-section .contact-form-area form input[type=submit]:hover {';
        $inline_style .= ( $button_hover ) ? 'background-color:'. $button_hover .';' : '';
        $inline_style .= '}';
      }
      if ( $input_border ) {
        $inline_style .= '.contact-pg-section-'.$e_uniqid .' .contact-form-area form input,.contact-pg-section-'.$e_uniqid .' .contact-form-area form textarea {';
        $inline_style .= ( $input_border ) ? 'border-color:'. $input_border .';' : '';
        $inline_style .= '}';
      }


      // add inline style
    add_inline_style( $inline_style );
    $styled_class  = ' contact-pg-section-'.$e_uniqid.' ';
    $contact_id = ( $contact_id ) ? $contact_id : 0;
    $image_url = wp_get_attachment_url( $image_url );
    $image_alt = get_post_meta( $image_url, '_wp_attachment_image_alt', true);
  ob_start(); ?>
  <?php if ( $contact_style == 'standard' ) { ?>
     <div class="contact-section <?php echo esc_attr( $class.$styled_class ); ?>">
        <div class="contact-form-area">
            <div class="contact-form-holder">
                 <?php echo do_shortcode( '[contact-form-7 id="'. $contact_id .'"]' ); ?>
            </div>
            <?php if($image_url){ ?>
            <div class="contact-pic">
                <img src="<?php echo esc_url( $image_url ); ?>" alt="<?php echo esc_attr( $image_alt ); ?>">
            </div>
          <?php } ?>
        </div>
    </div>
  <?php } else { ?>
    <div class="contact-pg-section <?php echo esc_attr( $class.$styled_class ); ?>">
      <div class="contact-area-left-col">
        <div class="section-title">
              <span><?php echo esc_html( $subtitle ) ?></span>
              <h2><?php echo esc_html( $title ) ?></h2>
          </div>
          <p><?php echo esc_html( $desc ) ?></p>
          <div class="contact-form-area">
              <div class="contact-form-holder">
                  <?php echo do_shortcode( '[contact-form-7 id="'. $contact_id .'"]' ); ?>
              </div>
              <?php if($image_url){ ?>
              <div class="contact-pic">
                  <img src="<?php echo esc_url( $image_url ); ?>" alt="<?php echo esc_attr( $image_alt ); ?>">
              </div>
              <?php } ?>
          </div>
      </div>
  </div>
  <?php }
   return ob_get_clean();
  }
}
add_shortcode( 'reg_ontact7', 'confin_contact7_function' );
