| 1 |
<?php |
| 2 |
|
| 3 |
if(!function_exists('blockspare_search_from_render')){ |
| 4 |
function blockspare_search_from_render($attributes) |
| 5 |
{ |
| 6 |
ob_start(); |
| 7 |
$unq_class = mt_rand(100000,999999); |
| 8 |
$blockuniqueclass = ''; |
| 9 |
|
| 10 |
if(!empty($attributes['uniqueClass'])){ |
| 11 |
$blockuniqueclass = $attributes['uniqueClass']; |
| 12 |
}else{ |
| 13 |
$blockuniqueclass = 'blockspare-posts-block-list-'.$unq_class; |
| 14 |
} |
| 15 |
|
| 16 |
$mainClass = $blockuniqueclass; |
| 17 |
$mainClass .=' ' . $attributes['blockHoverEffect']; |
| 18 |
|
| 19 |
$wrapClass = 'bs-search-wrapper bs-grid-' . $attributes['sectionAlign']; |
| 20 |
$toggleClass = 'bs-search-' . $attributes['sectionAlign']; |
| 21 |
if($attributes['searchStyle'] == "icon" && $attributes['iconOption'] == "dropdown") { |
| 22 |
$toggleClass .= ' bs-search-dropdown-toggle'; |
| 23 |
} |
| 24 |
if($attributes['searchStyle'] == "icon" && $attributes['iconOption'] == "overlay") { |
| 25 |
$toggleClass .= ' bs-site-search-toggle'; |
| 26 |
} |
| 27 |
if($attributes['searchStyle'] == "form") { |
| 28 |
$toggleClass .= ' bs-search-form-header'; |
| 29 |
} |
| 30 |
if( $attributes['animation']){ |
| 31 |
$toggleClass .= ' blockspare-block-animation ' . $attributes['animation']; |
| 32 |
} |
| 33 |
|
| 34 |
$iconClass = 'bs-search-icon--toggle blockspare-hover-item blockspare-hover-text ' . $attributes['searchIcon']; |
| 35 |
$alignclass = blockspare_checkalignment($attributes['align']); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
?> |
| 40 |
<div class="<?php echo esc_attr($mainClass);?> align<?php echo esc_attr($alignclass) ?>"> |
| 41 |
<section class="<?php echo esc_attr($wrapClass);?>"> |
| 42 |
<div class="<?php echo esc_attr($toggleClass);?>"> |
| 43 |
<?php if($attributes['searchStyle'] == "icon"){ ?> |
| 44 |
<button class="<?php echo esc_attr($iconClass);?>"> |
| 45 |
<span class="screen-reader-text"> |
| 46 |
Enter Keyword |
| 47 |
</span> |
| 48 |
</button> |
| 49 |
<?php if($attributes['iconOption'] == "dropdown"){ ?> |
| 50 |
<div class="bs-search--toggle-dropdown"> |
| 51 |
<div class="bs-search--toggle-dropdown-wrapper"> |
| 52 |
<?php echo blockspare_search_html($attributes);?> |
| 53 |
</div> |
| 54 |
</div> |
| 55 |
<?php } ?> |
| 56 |
<?php } ?> |
| 57 |
<?php if($attributes['searchStyle'] == "form"){ ?> |
| 58 |
<div class="bs-search-form--wrapper"> |
| 59 |
<?php echo blockspare_search_html($attributes);?> |
| 60 |
</div> |
| 61 |
<?php } ?> |
| 62 |
</div> |
| 63 |
<?php if($attributes['searchStyle'] == "icon" && $attributes['iconOption'] == "overlay"){ ?> |
| 64 |
<div class="bs-search--toggle"> |
| 65 |
<div class="bs-search-toggle--wrapper"> |
| 66 |
<?php echo blockspare_search_html($attributes);?> |
| 67 |
</div> |
| 68 |
<button class="bs--site-search-close fas fa-times"> |
| 69 |
<span class="screen-reader-text">Close</span> |
| 70 |
</button> |
| 71 |
</div> |
| 72 |
<?php } ?> |
| 73 |
</section> |
| 74 |
</div> |
| 75 |
|
| 76 |
<?php |
| 77 |
$data = search_style_control($blockuniqueclass ,$attributes); |
| 78 |
return $data .= ob_get_clean(); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
function blockspare_search_html($attributes){ |
| 83 |
ob_start(); |
| 84 |
$btnIconClass = 'btn-bs-search-form'; |
| 85 |
if($attributes['buttonType'] == "icon") { |
| 86 |
$btnIconClass .= ' ' . $attributes['buttonIcon']; |
| 87 |
} |
| 88 |
?> |
| 89 |
<div |
| 90 |
class="bs--search-sidebar-wrapper" |
| 91 |
aria-expanded="false" |
| 92 |
role="form" |
| 93 |
> |
| 94 |
<form role="search" action="<?php echo home_url( '/' ); ?>" method="get" class="search-form site-search-form blockspare-hover-item"> |
| 95 |
<span class="screen-reader-text">Search for:</span> |
| 96 |
|
| 97 |
<input |
| 98 |
type="text" |
| 99 |
class="search-field site-search-field" |
| 100 |
placeholder="<?php echo esc_attr($attributes['placeholder']);?>" |
| 101 |
name="s" |
| 102 |
/> |
| 103 |
<button |
| 104 |
type="submit" |
| 105 |
class="<?php echo esc_attr($btnIconClass);?>" |
| 106 |
> |
| 107 |
<?php if($attributes['buttonType'] == "icon"){ ?> |
| 108 |
<span class="screen-reader-text">Search</span> |
| 109 |
<?php } ?> |
| 110 |
<?php if($attributes['buttonType'] == "text"){ ?> |
| 111 |
<?php echo $attributes['buttonLabel'] != "" ? $attributes['buttonLabel'] : "Search";?> |
| 112 |
<?php } ?> |
| 113 |
</button> |
| 114 |
</form> |
| 115 |
</div> |
| 116 |
|
| 117 |
|
| 118 |
<?php return ob_get_clean();} |
| 119 |
|
| 120 |
/** |
| 121 |
* Registers the post grid block on server |
| 122 |
*/ |
| 123 |
|
| 124 |
if(!function_exists('blockspare_search_from_init')){ |
| 125 |
function blockspare_search_from_init() { |
| 126 |
if (!function_exists('register_block_type')) { |
| 127 |
return; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
ob_start(); |
| 132 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/other-block/search/block.json'; |
| 133 |
$metadata = json_decode(ob_get_clean(), true); |
| 134 |
|
| 135 |
/* Block attributes */ |
| 136 |
register_block_type( |
| 137 |
'blockspare/search', |
| 138 |
array( |
| 139 |
'attributes' =>$metadata['attributes'], |
| 140 |
'render_callback' => 'blockspare_search_from_render', |
| 141 |
) |
| 142 |
); |
| 143 |
} |
| 144 |
|
| 145 |
add_action('init', 'blockspare_search_from_init'); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
} |
| 152 |
|
| 153 |
if(!function_exists('search_style_control')){ |
| 154 |
function search_style_control($blockuniqueclass ,$attributes) |
| 155 |
{ |
| 156 |
$block_content = ''; |
| 157 |
$block_content .= '<style type="text/css">'; |
| 158 |
|
| 159 |
//icon font size |
| 160 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .bs-search-icon--toggle{ |
| 161 |
font-size:' . $attributes['iconSize'] . 'px; |
| 162 |
}'; |
| 163 |
|
| 164 |
//search form bordar radius |
| 165 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .site-search-form{ |
| 166 |
border-radius:' . $attributes['borderRadius'] . 'px; |
| 167 |
}'; |
| 168 |
|
| 169 |
//search form height |
| 170 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .bs-search-form-header .site-search-field{ |
| 171 |
height:' . $attributes['height'] . 'px; |
| 172 |
}'; |
| 173 |
|
| 174 |
//search form background color |
| 175 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .bs--search-sidebar-wrapper .site-search-form{ |
| 176 |
background-color:' . $attributes['bgColor'] . '; |
| 177 |
}'; |
| 178 |
|
| 179 |
//search button background color |
| 180 |
if(isset($attributes['buttonBgColor'])){ |
| 181 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .bs--search-sidebar-wrapper .btn-bs-search-form{ |
| 182 |
background-color:' . $attributes['buttonBgColor'] . '; |
| 183 |
}'; |
| 184 |
} |
| 185 |
|
| 186 |
//placeholder color |
| 187 |
if(isset($attributes['placeholderTextColor'])){ |
| 188 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .site-search-field::placeholder{ |
| 189 |
color:' . $attributes['placeholderTextColor'] . '; |
| 190 |
}'; |
| 191 |
} |
| 192 |
|
| 193 |
//input color |
| 194 |
if(isset($attributes['inputTextColor'])){ |
| 195 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .site-search-field{ |
| 196 |
color:' . $attributes['inputTextColor'] . '; |
| 197 |
}'; |
| 198 |
} |
| 199 |
|
| 200 |
//close icon color |
| 201 |
if(isset($attributes['closeIconColor'])){ |
| 202 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .bs--site-search-close{ |
| 203 |
color:' . $attributes['closeIconColor'] . '; |
| 204 |
}'; |
| 205 |
} |
| 206 |
|
| 207 |
//icon color |
| 208 |
if($attributes['searchStyle'] == "icon" || $attributes['buttonType'] == "icon") { |
| 209 |
if(isset($attributes['iconColor'])){ |
| 210 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .bs-search-icon--toggle{ |
| 211 |
color:' . $attributes['iconColor'] . '; |
| 212 |
}'; |
| 213 |
} |
| 214 |
} |
| 215 |
if($attributes['searchStyle'] == "icon" || $attributes['buttonType'] == "icon") { |
| 216 |
if(isset($attributes['formIconColor'])){ |
| 217 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .btn-bs-search-form::before{ |
| 218 |
color:' . $attributes['formIconColor'] . '; |
| 219 |
}'; |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
//button text color |
| 224 |
if($attributes['buttonType'] == "text") { |
| 225 |
if(isset($attributes['buttonTextColor'])){ |
| 226 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .bs--search-sidebar-wrapper .btn-bs-search-form{ |
| 227 |
color:' . $attributes['buttonTextColor'] . '; |
| 228 |
}'; |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
//toogle icon Gaps |
| 233 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .bs-search-icon--toggle{ |
| 234 |
padding-top:' . $attributes['toggleIconPaddingTop'] . 'px; |
| 235 |
padding-right:' . $attributes['toggleIconPaddingRight'] . 'px; |
| 236 |
padding-bottom:' . $attributes['toggleIconPaddingBottom'] . 'px; |
| 237 |
padding-left:' . $attributes['toggleIconPaddingLeft'] . 'px; |
| 238 |
}'; |
| 239 |
|
| 240 |
//search form Gaps |
| 241 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .bs--search-sidebar-wrapper .site-search-form{ |
| 242 |
padding-top:' . $attributes['searchFormPaddingTop'] . 'px; |
| 243 |
padding-right:' . $attributes['searchFormPaddingRight'] . 'px; |
| 244 |
padding-bottom:' . $attributes['searchFormPaddingBottom'] . 'px; |
| 245 |
padding-left:' . $attributes['searchFormPaddingLeft'] . 'px; |
| 246 |
}'; |
| 247 |
|
| 248 |
//Block Gaps |
| 249 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper{ |
| 250 |
margin-top:' . $attributes['marginTop'] . 'px; |
| 251 |
margin-right:' . $attributes['marginRight'] . 'px; |
| 252 |
margin-bottom:' . $attributes['marginBottom'] . 'px; |
| 253 |
margin-left:' . $attributes['marginLeft'] . 'px; |
| 254 |
padding-top:' . $attributes['paddingTop'] . 'px; |
| 255 |
padding-right:' . $attributes['paddingRight'] . 'px; |
| 256 |
padding-bottom:' . $attributes['paddingBottom'] . 'px; |
| 257 |
padding-left:' . $attributes['paddingLeft'] . 'px; |
| 258 |
}'; |
| 259 |
|
| 260 |
//search input gaps |
| 261 |
if($attributes['searchStyle'] == "form") { |
| 262 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .bs-search-form-header .site-search-field{ |
| 263 |
padding-right:' . $attributes['searchInputPaddingRight'] . 'px; |
| 264 |
padding-left:' . $attributes['searchInputPaddingLeft'] . 'px; |
| 265 |
}'; |
| 266 |
} |
| 267 |
|
| 268 |
//Font Settings |
| 269 |
|
| 270 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .site-search-field::placeholder{ |
| 271 |
font-size: ' . $attributes['placeholderFontSize'] . $attributes['placeholderFontSizeType'] . '; |
| 272 |
'.bscheckFontfamily($attributes['placeholderFontFamily']).'; |
| 273 |
'.bscheckFontfamilyWeight($attributes['placeholderFontWeight']).'; |
| 274 |
|
| 275 |
}'; |
| 276 |
|
| 277 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .site-search-field{ |
| 278 |
font-size: ' . $attributes['inputFontSize'] . $attributes['inputFontSizeType'] . '; |
| 279 |
'.bscheckFontfamily($attributes['inputFontFamily']).'; |
| 280 |
'.bscheckFontfamilyWeight($attributes['inputFontWeight']).'; |
| 281 |
}'; |
| 282 |
|
| 283 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .bs--search-sidebar-wrapper .btn-bs-search-form:not(.fas){ |
| 284 |
font-size: ' . $attributes['searchFontSize'] . $attributes['searchFontSizeType'] . '; |
| 285 |
'.bscheckFontfamily($attributes['searchFontFamily']).'; |
| 286 |
'.bscheckFontfamilyWeight($attributes['searchFontWeight']).'; |
| 287 |
}'; |
| 288 |
|
| 289 |
$block_content .= '@media (max-width: 1025px) { '; |
| 290 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .site-search-field::placeholder{ |
| 291 |
font-size: ' . $attributes['placeholderFontSizeTablet'] . $attributes['placeholderFontSizeType'] . '; |
| 292 |
}'; |
| 293 |
|
| 294 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .site-search-field{ |
| 295 |
font-size: ' . $attributes['inputFontSizeTablet'] . $attributes['inputFontSizeType'] . '; |
| 296 |
}'; |
| 297 |
|
| 298 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .bs--search-sidebar-wrapper .btn-bs-search-form:not(.fas){ |
| 299 |
font-size: ' . $attributes['searchFontSizeTablet'] . $attributes['searchFontSizeType'] . '; |
| 300 |
}'; |
| 301 |
$block_content .= '}'; |
| 302 |
|
| 303 |
$block_content .= '@media (max-width: 767px) { '; |
| 304 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .site-search-field::placeholder{ |
| 305 |
font-size: ' . $attributes['placeholderFontSizeMobile'] . $attributes['placeholderFontSizeType'] . '; |
| 306 |
}'; |
| 307 |
|
| 308 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .site-search-field{ |
| 309 |
font-size: ' . $attributes['inputFontSizeMobile'] . $attributes['inputFontSizeType'] . '; |
| 310 |
}'; |
| 311 |
|
| 312 |
$block_content .= ' .' . $blockuniqueclass . ' .bs-search-wrapper .bs--search-sidebar-wrapper .btn-bs-search-form:not(.fas){ |
| 313 |
font-size: ' . $attributes['searchFontSizeMobile'] . $attributes['searchFontSizeType'] . '; |
| 314 |
}'; |
| 315 |
$block_content .= '}'; |
| 316 |
|
| 317 |
|
| 318 |
$block_content .= '</style>'; |
| 319 |
return $block_content; |
| 320 |
} |
| 321 |
} |