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