PluginProbe
Post Grid Gutenberg Blocks – PostX / trunk
Post Grid Gutenberg Blocks – PostX vtrunk
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 5.0.17 2.1.1 2.1.2 2.1.3 All 236 releases
ultimate-post / blocks / Advanced_Search.php

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

167 lines 8.8 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 $is_visible = true;
77 if ( isset( $attr['blockPubDate'] ) && $attr['blockPubDate'] != 'empty' ) {
78 $is_visible = ultimate_post()->is_pro_feature_visible( $attr['blockPubDate'] );
79 }
80
81 $is_active = ultimate_post()->is_lc_active();
82
83 if ( $is_active || $is_visible ) {
84 $attr = wp_parse_args( $attr, $this->get_attributes() );
85
86 $attr['blockId'] = sanitize_html_class( $attr['blockId'] );
87 $attr['className'] = isset( $attr['className'] ) && $attr['className'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['className'] ) : '';
88 $attr['align'] = isset( $attr['align'] ) && $attr['align'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['align'] ) : '';
89 $attr['popupAnimation'] = sanitize_html_class( $attr['popupAnimation'] );
90 $attr['btnNewTab'] = $attr['btnNewTab'] == true;
91 $attr['searchAjaxEnable'] = $attr['searchAjaxEnable'] == true;
92 $attr['enableSearchPage'] = $attr['enableSearchPage'] == true;
93 $attr['resImageEnable'] = $attr['resImageEnable'] == true;
94 $attr['resAuthEnable'] = $attr['resAuthEnable'] == true;
95 $attr['resDateEnable'] = $attr['resDateEnable'] == true;
96 $attr['resExcerptEnable'] = $attr['resExcerptEnable'] == true;
97 $attr['moreResultsbtn'] = $attr['moreResultsbtn'] == true;
98 $attr['resCatEnable'] = $attr['resCatEnable'] == true;
99 $attr['resExcerptLimit'] = sanitize_html_class( $attr['resExcerptLimit'] );
100 $attr['moreResultPosts'] = sanitize_html_class( $attr['moreResultPosts'] );
101 $attr['searchPopupPosition'] = sanitize_html_class( $attr['searchPopupPosition'] );
102 $attr['searchFormStyle'] = sanitize_html_class( $attr['searchFormStyle'] );
103 $attr['searchPopupIconStyle'] = sanitize_html_class( $attr['searchPopupIconStyle'] );
104
105 $allowed_html_tags = ultimate_post()->ultp_allowed_html_tags();
106 $attr['windowpopupText'] = wp_kses( $attr['windowpopupText'], $allowed_html_tags );
107 $attr['searchnoresult'] = wp_kses( $attr['searchnoresult'], $allowed_html_tags );
108 $attr['moreResultsText'] = wp_kses( $attr['moreResultsText'], $allowed_html_tags );
109 $attr['searchButtonText'] = wp_kses( $attr['searchButtonText'], $allowed_html_tags );
110 $attr['searchInputPlaceholder'] = wp_kses( $attr['searchInputPlaceholder'], $allowed_html_tags );
111
112 $data_var = 'data-searchPostType="' . esc_attr( json_decode( wp_json_encode( $attr['searchPostType'] ) ) ) . '"';
113 $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'] : '' ) . '">';
114 $wraper_before .= '<div class="ultp-block-wrapper">';
115 $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'] ) . '"
116 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 . '>';
117 if ( $attr['searchPopup'] ) {
118 $content .= $this->renderSearchButton( $attr['searchPopupIconStyle'], $attr['searchBtnText'], $attr['searchBtnIcon'], $attr['searchButtonText'] );
119 }
120 if ( $attr['searchPopup'] == false ) {
121 $content .= $this->renderSearchForm( $attr['searchFormStyle'], $attr['searchBtnText'], $attr['searchBtnIcon'], $attr );
122 }
123 if ( $attr['searchPopup'] ) {
124 $popup_content .= '<div class="ultp-search-canvas">';
125
126 $popup_content .= '<div class="ultp-canvas-header">';
127 if ( $attr['windowpopupHeading'] ) {
128 $popup_content .= '<div class="ultp-search-popup-heading">' . $attr['windowpopupText'] . '</div>';
129 }
130 $popup_content .= $this->renderSearchForm( $attr['searchFormStyle'], $attr['searchBtnText'], $attr['searchBtnIcon'], $attr );
131 $popup_content .= '</div>';
132 $popup_content .= '<div class="ultp-popupclose-icon">' . ultimate_post()->get_svg_icon( 'close_line' ) . '</div>';
133 $popup_content .= '</div>';
134 if ( $attr['popupAnimation'] == 'popup' ) {
135 $content .= $popup_content;
136 } else {
137 $content .= $popup_content;
138 }
139 }
140 $content .= '</div>';
141 $wraper_after .= '</div>';
142 $wraper_after .= '</div>';
143 return $wraper_before . $content . $wraper_after;
144 }
145 }
146
147 public function renderSearchButton( $style, $textEnable = true, $iconEnable = true, $searchButtonText = '' ) {
148 $textShow = $textEnable && $style != 'popup-icon1';
149 $result = '';
150 $result .= '<div class=" ' . ( $style ? 'ultp-searchpopup-icon ultp-searchbtn-' . $style : 'ultp-search-button' ) . '">';
151 $result .= ( $style || $iconEnable ) ? ultimate_post()->get_svg_icon( 'search_line' ) : '';
152 $result .= $textShow ? '<span class="ultp-search-button__text"> ' . $searchButtonText . ' </span>' : '';
153 $result .= '</div>';
154 return $result;
155 }
156
157 public function renderSearchForm( $searchFormStyle, $searchBtnText, $searchBtnIcon, $attr ) {
158 $dt = is_search() ? get_search_query( true ) : '';
159 $searchForm = '';
160 $searchForm .= '<div class="ultp-searchform-content ultp-searchform-' . $searchFormStyle . '">';
161 $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>';
162 $searchForm .= $this->renderSearchButton( false, $attr['searchBtnText'], $attr['searchBtnIcon'], $attr['searchButtonText'] );
163 $searchForm .= '</div>';
164 return $searchForm;
165 }
166 }
167