| 1 |
<?php |
| 2 |
namespace ULTP\blocks; |
| 3 |
|
| 4 |
defined('ABSPATH') || exit; |
| 5 |
|
| 6 |
class Advanced_Search { |
| 7 |
public function __construct() { |
| 8 |
add_action( 'init', array( $this, 'register' ) ); |
| 9 |
} |
| 10 |
|
| 11 |
public function get_attributes() { |
| 12 |
return array( |
| 13 |
'advanceId' => '', |
| 14 |
'blockId' => '', |
| 15 |
'advanceCss' => '', |
| 16 |
// General Content Setting |
| 17 |
'searchFormStyle' => 'input1', |
| 18 |
'searchPopup' => false, |
| 19 |
'searchPopupIconStyle' => 'popup-icon1', |
| 20 |
'searchAjaxEnable' => true, |
| 21 |
'searchResultLayout' => 'res', |
| 22 |
'searchnoresult' => 'No Results Found', |
| 23 |
'searchPostType' => '', |
| 24 |
|
| 25 |
// Popup Canvas |
| 26 |
'popupAnimation' => 'popup', |
| 27 |
|
| 28 |
'searchPopupPosition' => 'right', |
| 29 |
'popupCloseIconSeparator' => 'Close Icon Style', |
| 30 |
'windowpopupHeading' => true, |
| 31 |
'windowpopupText' => 'Search The Query', |
| 32 |
|
| 33 |
// Search Button Style |
| 34 |
'searchBtnEnable' => false, |
| 35 |
'btnNewTab' => false, |
| 36 |
'enableSearchPage' => true, |
| 37 |
'searchButtonText' => 'Search', |
| 38 |
'searchBtnText' => true, |
| 39 |
'searchBtnIcon' => true, |
| 40 |
'searchIconAfterText' => false, |
| 41 |
|
| 42 |
// Search Form Style |
| 43 |
'searchInputPlaceholder' => 'Search...', |
| 44 |
|
| 45 |
// Search Result Settings |
| 46 |
'resExcerptEnable' => true, |
| 47 |
'resCatEnable' => true, |
| 48 |
'resAuthEnable' => true, |
| 49 |
'resDateEnable' => true, |
| 50 |
'resImageEnable' => true, |
| 51 |
'resExcerptLimit' => '25', |
| 52 |
|
| 53 |
// Search Result Settings |
| 54 |
'moreResultsbtn' => true, |
| 55 |
'moreResultPosts' => 3, |
| 56 |
'moreResultsText' => 'View More Results', |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
public function register() { |
| 61 |
register_block_type( 'ultimate-post/advanced-search', |
| 62 |
array( |
| 63 |
'editor_script' => 'ultp-blocks-editor-script', |
| 64 |
'editor_style' => 'ultp-blocks-editor-css', |
| 65 |
'render_callback' => array( $this, 'content' ) |
| 66 |
) |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
public function content($attr, $noAjax) { |
| 71 |
$wraper_before = $wraper_after = $content = $popup_content = ''; |
| 72 |
$block_name = 'advanced-search'; |
| 73 |
$is_active = ultimate_post()->is_lc_active(); |
| 74 |
|
| 75 |
if ( $is_active ) { |
| 76 |
$attr = wp_parse_args($attr, $this->get_attributes()); |
| 77 |
|
| 78 |
$attr['blockId'] = sanitize_html_class( $attr['blockId'] ); |
| 79 |
$attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : ''; |
| 80 |
$attr['align'] = isset($attr['align']) && $attr['align'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['align']) : ''; |
| 81 |
$attr['popupAnimation'] = sanitize_html_class( $attr['popupAnimation'] ); |
| 82 |
$attr['btnNewTab'] = $attr['btnNewTab'] == true; |
| 83 |
$attr['searchAjaxEnable'] = $attr['searchAjaxEnable'] == true; |
| 84 |
$attr['enableSearchPage'] = $attr['enableSearchPage'] == true; |
| 85 |
$attr['resImageEnable'] = $attr['resImageEnable'] == true; |
| 86 |
$attr['resAuthEnable'] = $attr['resAuthEnable'] == true; |
| 87 |
$attr['resDateEnable'] = $attr['resDateEnable'] == true; |
| 88 |
$attr['resExcerptEnable'] = $attr['resExcerptEnable'] == true; |
| 89 |
$attr['moreResultsbtn'] = $attr['moreResultsbtn'] == true; |
| 90 |
$attr['resCatEnable'] = $attr['resCatEnable'] == true; |
| 91 |
$attr['resExcerptLimit'] = sanitize_html_class( $attr['resExcerptLimit'] ); |
| 92 |
$attr['moreResultPosts'] = sanitize_html_class( $attr['moreResultPosts'] ); |
| 93 |
$attr['searchPopupPosition'] = sanitize_html_class( $attr['searchPopupPosition'] ); |
| 94 |
$attr['searchFormStyle'] = sanitize_html_class( $attr['searchFormStyle'] ); |
| 95 |
$attr['searchPopupIconStyle'] = sanitize_html_class( $attr['searchPopupIconStyle'] ); |
| 96 |
|
| 97 |
$allowed_html_tags = ultimate_post()->ultp_allowed_html_tags(); |
| 98 |
$attr['windowpopupText'] = wp_kses($attr['windowpopupText'], $allowed_html_tags); |
| 99 |
$attr['searchnoresult'] = wp_kses($attr['searchnoresult'], $allowed_html_tags); |
| 100 |
$attr['moreResultsText'] = wp_kses($attr['moreResultsText'], $allowed_html_tags); |
| 101 |
$attr['searchButtonText'] = wp_kses($attr['searchButtonText'], $allowed_html_tags); |
| 102 |
$attr['searchInputPlaceholder'] = wp_kses($attr['searchInputPlaceholder'], $allowed_html_tags); |
| 103 |
|
| 104 |
$data_var = "data-searchPostType=".json_decode(wp_json_encode($attr['searchPostType'])); |
| 105 |
$wraper_before .= '<div '.($attr['advanceId']?'id="'.sanitize_html_class( $attr['advanceId'] ).'" ':'').' class="wp-block-ultimate-post-'.$block_name.' ultp-block-'.sanitize_html_class( $attr["blockId"] ).''.( $attr["align"] ? ' align' .$attr["align"]:'').''.( $attr["className"] ? ' '. $attr["className"] :'').'">'; |
| 106 |
$wraper_before .= '<div class="ultp-block-wrapper">'; |
| 107 |
$content .= '<div class="ultp-search-container ultp-search-frontend'.($attr['searchPopup'] ? ' ultp-search-animation-'. $attr['popupAnimation'] :'').'" data-ajax="'.$attr['searchAjaxEnable'].'" data-gosearch="'.$attr['enableSearchPage'].'" data-enablenewtab="'.$attr['btnNewTab'].'" data-blockId="'.$attr['blockId'].'" |
| 108 |
data-image="'.$attr['resImageEnable'].'" data-author='.$attr['resAuthEnable'].' data-date="'.$attr['resDateEnable'].'" data-excerpt="'.$attr['resExcerptEnable'].'" data-excerptLimit="'.$attr['resExcerptLimit'].'" data-allresult="'.$attr['moreResultsbtn'].'" data-catEnable="'.$attr['resCatEnable'].'" data-postno="'.$attr['moreResultPosts'].'" '.($attr['searchPopup'] ? 'data-popuptype="'.$attr['popupAnimation'].'" ' : '').' '.($attr['searchAjaxEnable'] ? 'data-noresultext="'.$attr['searchnoresult'].'" ' : '').' '.($attr['moreResultsbtn'] ? 'data-viewmoretext="'.$attr['moreResultsText'].'" ' : '').' data-popupposition="'.$attr['searchPopupPosition'].'" '.$data_var.'>'; |
| 109 |
if ( $attr['searchPopup'] ) { |
| 110 |
$content .= $this->renderSearchButton($attr['searchPopupIconStyle'], $attr['searchBtnText'], $attr['searchBtnIcon'] ,$attr['searchButtonText']); |
| 111 |
} |
| 112 |
if ( $attr['searchPopup'] == false ) { |
| 113 |
$content .= $this->renderSearchForm($attr['searchFormStyle'], $attr['searchBtnText'], $attr['searchBtnIcon'], $attr); |
| 114 |
} |
| 115 |
if ( $attr['searchPopup'] ) { |
| 116 |
$popup_content .= '<div class="ultp-search-canvas">'; |
| 117 |
|
| 118 |
$popup_content .= '<div class="ultp-canvas-header">'; |
| 119 |
if($attr['windowpopupHeading']){ |
| 120 |
$popup_content .= '<div class="ultp-search-popup-heading">'.$attr['windowpopupText'].'</div>'; |
| 121 |
} |
| 122 |
$popup_content .= $this->renderSearchForm($attr['searchFormStyle'], $attr['searchBtnText'], $attr['searchBtnIcon'], $attr); |
| 123 |
$popup_content .= '</div>'; |
| 124 |
$popup_content .= '<div class="ultp-popupclose-icon">'.ultimate_post()->get_svg_icon('close_line').'</div>'; |
| 125 |
$popup_content .= '</div>'; |
| 126 |
if($attr['popupAnimation'] == 'popup'){ |
| 127 |
$content .= $popup_content; |
| 128 |
} else { |
| 129 |
$content .= $popup_content; |
| 130 |
} |
| 131 |
} |
| 132 |
$content .= '</div>'; |
| 133 |
$wraper_after .= '</div>'; |
| 134 |
$wraper_after .= '</div>'; |
| 135 |
return $wraper_before.$content.$wraper_after; |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
public function renderSearchButton( $style, $textEnable = true, $iconEnable = true, $searchButtonText = '' ) { |
| 140 |
$textShow = $textEnable && $style != "popup-icon1"; |
| 141 |
$result = ''; |
| 142 |
$result .= '<div class=" '.($style ? 'ultp-searchpopup-icon ultp-searchbtn-'.$style : 'ultp-search-button').'">'; |
| 143 |
$result .= ($style || $iconEnable) ? ultimate_post()->get_svg_icon('search_line') : ''; |
| 144 |
$result .= $textShow ? '<span class="ultp-search-button__text"> '.$searchButtonText.' </span>' : ''; |
| 145 |
$result .= '</div>'; |
| 146 |
return $result; |
| 147 |
} |
| 148 |
|
| 149 |
public function renderSearchForm( $searchFormStyle, $searchBtnText, $searchBtnIcon, $attr ) { |
| 150 |
$dt = is_search() ? get_search_query(true) : ''; |
| 151 |
$searchForm = ''; |
| 152 |
$searchForm .= '<div class="ultp-searchform-content ultp-searchform-'.$searchFormStyle.'">'; |
| 153 |
$searchForm .= '<div class="ultp-search-inputwrap"> <input type="text" value="'.$dt.'" class="ultp-searchres-input" placeholder="'.$attr['searchInputPlaceholder'].'"/> <span class="ultp-search-clear" data-blockid="'.$attr["blockId"].'">'.ultimate_post()->get_svg_icon('close_line').'</span> </div>'; |
| 154 |
$searchForm .= $this->renderSearchButton(false, $attr['searchBtnText'], $attr['searchBtnIcon'] ,$attr['searchButtonText']); |
| 155 |
$searchForm .= '</div>'; |
| 156 |
return $searchForm; |
| 157 |
} |
| 158 |
} |