PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.1.1
Post Grid Gutenberg Blocks – PostX v5.1.1
5.1.1 5.1.0 5.0.41 5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 All 240 releases
ultimate-post / blocks / Advanced_Search.php

Advanced_Search.php in Post Grid Gutenberg Blocks – PostX 5.1.1, at blocks/Advanced_Search.php

158 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ULTP\blocks;
4
5 defined( 'ABSPATH' ) || exit;
6
7 class Advanced_Search {
8 public function __construct() {
9 add_action( 'init', array( $this, 'register' ) );
10 }
11
12 public function get_attributes() {
13 return array(
14 'advanceId' => '',
15 'blockId' => '',
16 'advanceCss' => '',
17 // General Content Setting
18 'searchFormStyle' => 'input1',
19 'searchPopup' => false,
20 'searchPopupIconStyle' => 'popup-icon1',
21 'searchAjaxEnable' => true,
22 'searchResultLayout' => 'res',
23 'searchnoresult' => 'No Results Found',
24 'searchPostType' => '',
25
26 // Popup Canvas
27 'popupAnimation' => 'popup',
28
29 'searchPopupPosition' => 'right',
30 'popupCloseIconSeparator' => 'Close Icon Style',
31 'windowpopupHeading' => true,
32 'windowpopupText' => 'Search The Query',
33
34 // Search Button Style
35 'searchBtnEnable' => false,
36 'btnNewTab' => false,
37 'enableSearchPage' => true,
38 'searchButtonText' => 'Search',
39 'searchBtnText' => true,
40 'searchBtnIcon' => true,
41 'searchIconAfterText' => false,
42
43 // Search Form Style
44 'searchInputPlaceholder' => 'Search...',
45
46 // Search Result Settings
47 'resExcerptEnable' => true,
48 'resCatEnable' => true,
49 'resAuthEnable' => true,
50 'resDateEnable' => true,
51 'resImageEnable' => true,
52 'resExcerptLimit' => '25',
53
54 // Search Result Settings
55 'moreResultsbtn' => true,
56 'moreResultPosts' => 3,
57 'moreResultsText' => 'View More Results',
58 );
59 }
60
61 public function register() {
62 register_block_type(
63 'ultimate-post/advanced-search',
64 array(
65 'editor_script' => 'ultp-blocks-editor-script',
66 'editor_style' => 'ultp-blocks-editor-css',
67 'render_callback' => array( $this, 'content' ),
68 )
69 );
70 }
71
72 public function content( $attr, $noAjax ) {
73 $wraper_before = $wraper_after = $content = $popup_content = '';
74 $block_name = 'advanced-search';
75
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="' . esc_attr( 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="' . esc_attr( $attr['searchAjaxEnable'] ) . '" data-gosearch="' . esc_attr( $attr['enableSearchPage'] ) . '" data-enablenewtab="' . esc_attr( $attr['btnNewTab'] ) . '" data-blockId="' . esc_attr( $attr['blockId'] ) . '"
108 data-image="' . esc_attr( $attr['resImageEnable'] ) . '" data-author="' . esc_attr( $attr['resAuthEnable'] ) . '" data-date="' . esc_attr( $attr['resDateEnable'] ) . '" data-excerpt="' . esc_attr( $attr['resExcerptEnable'] ) . '" data-excerptLimit="' . esc_attr( $attr['resExcerptLimit'] ) . '" data-allresult="' . esc_attr( $attr['moreResultsbtn'] ) . '" data-catEnable="' . esc_attr( $attr['resCatEnable'] ) . '" data-postno="' . esc_attr( $attr['moreResultPosts'] ) . '" ' . ( $attr['searchPopup'] ? 'data-popuptype="' . esc_attr( $attr['popupAnimation'] ) . '" ' : '' ) . ' ' . ( $attr['searchAjaxEnable'] ? 'data-noresultext="' . esc_attr( $attr['searchnoresult'] ) . '" ' : '' ) . ' ' . ( $attr['moreResultsbtn'] ? 'data-viewmoretext="' . esc_attr( $attr['moreResultsText'] ) . '" ' : '' ) . ' data-popupposition="' . esc_attr( $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 public function renderSearchButton( $style, $textEnable = true, $iconEnable = true, $searchButtonText = '' ) {
139 $textShow = $textEnable && $style != 'popup-icon1';
140 $result = '';
141 $result .= '<div class=" ' . ( $style ? 'ultp-searchpopup-icon ultp-searchbtn-' . $style : 'ultp-search-button' ) . '">';
142 $result .= ( $style || $iconEnable ) ? ultimate_post()->get_svg_icon( 'search_line' ) : '';
143 $result .= $textShow ? '<span class="ultp-search-button__text"> ' . $searchButtonText . ' </span>' : '';
144 $result .= '</div>';
145 return $result;
146 }
147
148 public function renderSearchForm( $searchFormStyle, $searchBtnText, $searchBtnIcon, $attr ) {
149 $dt = is_search() ? get_search_query( true ) : '';
150 $searchForm = '';
151 $searchForm .= '<div class="ultp-searchform-content ultp-searchform-' . $searchFormStyle . '">';
152 $searchForm .= '<div class="ultp-search-inputwrap"> <input type="text" value="' . esc_attr( $dt ) . '" class="ultp-searchres-input" placeholder="' . esc_attr( $attr['searchInputPlaceholder'] ) . '"/> <span class="ultp-search-clear" data-blockid="' . $attr['blockId'] . '">' . ultimate_post()->get_svg_icon( 'close_line' ) . '</span> </div>';
153 $searchForm .= $this->renderSearchButton( false, $attr['searchBtnText'], $attr['searchBtnIcon'], $attr['searchButtonText'] );
154 $searchForm .= '</div>';
155 return $searchForm;
156 }
157 }
158