Advertisement
Guest User

templates/elements/search.php

a guest
Mar 29th, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. <?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
  2.  
  3. /**
  4. * Output search element
  5. *
  6. * @var $text string Placeholder Text
  7. * @var $layout string Layout: 'simple' / 'modern' / 'fulwidth' / 'fullscreen'
  8. * @var $width int Field width
  9. * @var $design_options array
  10. * @var $product_search bool Whether to search for WooCommerce products only
  11. * @var $classes string
  12. * @var $id string
  13. */
  14.  
  15. $_atts['class'] = 'w-search';
  16. $_atts['class'] .= isset( $classes ) ? $classes : '';
  17.  
  18. // Force "Simple" layout for shortcode
  19. if ( $us_elm_context == 'shortcode' ) {
  20. $layout = 'simple';
  21. }
  22.  
  23. $_atts['class'] .= ' layout_' . $layout;
  24.  
  25. if ( us_get_option( 'ripple_effect' ) ) {
  26. $_atts['class'] .= ' with_ripple';
  27. }
  28. if ( ! empty( $el_class ) ) {
  29. $_atts['class'] .= ' ' . $el_class;
  30. }
  31.  
  32. if ( ! empty( $el_id ) ) {
  33. $_atts['id'] = $el_id;
  34. }
  35. if ( us_amp() AND empty( $el_id ) ) {
  36. $_atts['id'] = str_replace( ':', '_', $id );;
  37. }
  38.  
  39. // Output the element
  40. $output = '<div ' . us_implode_atts( $_atts ) . '>';
  41.  
  42. // Additional block for Fullscreen layout, when Ripple Effect is enabled
  43. if ( $layout == 'fullscreen' AND us_get_option( 'ripple_effect' ) ) {
  44.  
  45. $output .= '<div class="w-search-background"';
  46. $output .= ' style="background:' . (
  47. ! empty( $field_bg_color )
  48. ? us_get_color( $field_bg_color, /* Gradient */ TRUE )
  49. : us_get_color( 'color_content_bg', /* Gradient */ TRUE )
  50. ) . '">';
  51. $output .= '</div>';
  52. }
  53.  
  54. // Add "Open" button
  55. if ( $us_elm_context != 'shortcode' ) {
  56. $open_btn_atts = array(
  57. 'class' => 'w-search-open',
  58. 'aria-label' => us_translate( 'Search' ),
  59. );
  60. if ( us_amp() ) {
  61. $open_btn_atts['on'] = 'tap:' . $_atts['id'] . '.toggleClass(class=\'active\')';
  62. } else {
  63. $open_btn_atts['href'] = 'javascript:void(0);';
  64. }
  65.  
  66. $output .= '<a ' . us_implode_atts( $open_btn_atts ) . '>';
  67. if ( ! empty( $icon ) ) {
  68. $output .= us_prepare_icon_tag( $icon );
  69. }
  70. $output .= '</a>';
  71. }
  72.  
  73. $output .= '<div class="w-search-form">';
  74. $output .= '<form class="w-form-row for_text" action="' . esc_attr( home_url( '/' ) ) . '" method="get">';
  75. $output .= '<div class="w-form-row-field">';
  76.  
  77. $input_atts = array(
  78. 'type' => 'text',
  79. 'name' => 's',
  80. 'id' => 'us_form_search_s',
  81. 'placeholder' => $text,
  82. 'aria-label' => $text,
  83. 'value' => esc_html( get_query_var( 's', /* Default */ '' ) ),
  84. );
  85.  
  86. // Add inline colors for shortcodes only
  87. if ( $us_elm_context == 'shortcode' ) {
  88. $input_atts['style'] = '';
  89.  
  90. if ( ! empty( $field_bg_color ) ) {
  91. $field_bg_color = us_get_color( $field_bg_color, /* Gradient */ TRUE );
  92. $input_atts['style'] .= sprintf( 'background:%s!important;', $field_bg_color );
  93. }
  94. if ( ! empty( $field_text_color ) ) {
  95. $field_text_color = us_get_color( $field_text_color );
  96. $input_atts['style'] .= sprintf( 'color:%s!important;', $field_text_color );
  97. }
  98. }
  99.  
  100. $output .= '<input ' . us_implode_atts( $input_atts ) . '/>';
  101.  
  102. // Additional hidden input for search Products only
  103. if ( ! empty( $product_search ) ) {
  104. $output .= '<input type="hidden" name="post_type" value="product" />';
  105. }
  106.  
  107. // Additional hidden input for Polylang and WPML Language code
  108. if ( has_filter( 'us_tr_current_language' ) ) {
  109. $output .= '<input type="hidden" name="lang" value="' . esc_attr( apply_filters( 'us_tr_current_language', NULL ) ) . '" />';
  110. }
  111.  
  112. $output .= '</div>';
  113.  
  114. // Clickable button for "Simple" layout only
  115. if ( $layout == 'simple' ) {
  116. $button_atts = array(
  117. 'class' => 'w-search-form-btn w-btn',
  118. 'type' => 'submit',
  119. 'aria-label' => us_translate( 'Search' ),
  120. );
  121.  
  122. // Add inline styles for shortcodes only
  123. if ( $us_elm_context == 'shortcode' ) {
  124. $button_atts['style'] = '';
  125.  
  126. if ( ! empty( $icon_size ) AND $icon_size != '1rem' ) {
  127. $button_atts['style'] .= sprintf( 'font-size:%s;', $icon_size );
  128. }
  129. if ( ! empty( $field_text_color ) ) {
  130. $field_text_color = us_get_color( $field_text_color );
  131. $button_atts['style'] .= sprintf( 'color:%s!important;', $field_text_color );
  132. }
  133. }
  134.  
  135. $output .= '<button ' . us_implode_atts( $button_atts ) . '>';
  136. if ( ! empty( $icon ) ) {
  137. $output .= us_prepare_icon_tag( $icon );
  138. }
  139. $output .= '</button>';
  140. }
  141.  
  142. // Add "Close" button
  143. if ( $us_elm_context != 'shortcode' ) {
  144. $close_btn_atts = array(
  145. 'class' => 'w-search-close',
  146. 'aria-label' => us_translate( 'Close' ),
  147. );
  148. if ( ! us_amp() ) {
  149. $close_btn_atts['href'] = 'javascript:void(0);';
  150. } elseif ( isset( $open_btn_atts['on'] ) ) {
  151. $close_btn_atts['on'] = $open_btn_atts['on'];
  152. }
  153. $output .= '<a ' . us_implode_atts( $close_btn_atts ) . '></a>';
  154. }
  155.  
  156. $output .= '</form></div></div>';
  157.  
  158. echo $output;
  159.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement