lightspeeddevelopment /
lsx-search
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * LSX Search Shortcode Class. |
||||
| 4 | * |
||||
| 5 | * @package lsx-search |
||||
| 6 | */ |
||||
| 7 | class LSX_Search_Shortcode { |
||||
|
0 ignored issues
–
show
Class name "LSX_Search_Shortcode" is not in PascalCase format
Classes in PHP are usually named in CamelCase. In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well. Thus the name database provider becomes Loading history...
|
|||||
| 8 | |||||
| 9 | /** |
||||
| 10 | * Construct method. |
||||
| 11 | */ |
||||
| 12 | public function __construct() { |
||||
|
0 ignored issues
–
show
|
|||||
| 13 | add_shortcode( 'lsx_search_form', array( $this, 'search_form' ) ); |
||||
| 14 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 15 | |||||
| 16 | /** |
||||
| 17 | * Outputs the appropriate search form |
||||
| 18 | */ |
||||
| 19 | public function search_form( $atts = array() ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 20 | $classes = 'search-form lsx-search-form form-inline'; |
||||
| 21 | |||||
| 22 | if ( isset( $atts['class'] ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 23 | $classes .= $atts['class']; |
||||
| 24 | } |
||||
| 25 | |||||
| 26 | $placeholder = __( 'Where do you want to go?', 'lsx-search' ); |
||||
| 27 | |||||
| 28 | if ( isset( $atts['placeholder'] ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 29 | $placeholder = $atts['placeholder']; |
||||
| 30 | } |
||||
| 31 | |||||
| 32 | $action = '/'; |
||||
| 33 | |||||
| 34 | if ( isset( $atts['action'] ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 35 | $action = $atts['action']; |
||||
| 36 | } |
||||
| 37 | |||||
| 38 | $method = 'get'; |
||||
| 39 | |||||
| 40 | if ( isset( $atts['method'] ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 41 | $method = $atts['method']; |
||||
| 42 | } |
||||
| 43 | |||||
| 44 | $button_label = __( 'Search', 'lsx-search' ); |
||||
| 45 | |||||
| 46 | if ( isset( $atts['button_label'] ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 47 | $button_label = $atts['button_label']; |
||||
| 48 | } |
||||
| 49 | |||||
| 50 | $button_class = 'btn cta-btn '; |
||||
| 51 | |||||
| 52 | if ( isset( $atts['button_class'] ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 53 | $button_class .= $atts['button_class']; |
||||
| 54 | } |
||||
| 55 | |||||
| 56 | $engine = false; |
||||
| 57 | |||||
| 58 | if ( isset( $atts['engine'] ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 59 | $engine = $atts['engine']; |
||||
| 60 | } |
||||
| 61 | |||||
| 62 | $engine_select = false; |
||||
| 63 | |||||
| 64 | if ( isset( $atts['engine_select'] ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 65 | $engine_select = true; |
||||
| 66 | } |
||||
| 67 | |||||
| 68 | $display_search_field = true; |
||||
| 69 | |||||
| 70 | if ( isset( $atts['search_field'] ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 71 | $display_search_field = (boolean) $atts['search_field']; |
||||
|
0 ignored issues
–
show
|
|||||
| 72 | } |
||||
| 73 | |||||
| 74 | $facets = false; |
||||
| 75 | |||||
| 76 | if ( isset( $atts['facets'] ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 77 | $facets = $atts['facets']; |
||||
| 78 | } |
||||
| 79 | |||||
| 80 | $combo_box = false; |
||||
| 81 | |||||
| 82 | if ( isset( $atts['combo_box'] ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 83 | $combo_box = true; |
||||
| 84 | } |
||||
| 85 | |||||
| 86 | $return = ''; |
||||
| 87 | |||||
| 88 | ob_start(); ?> |
||||
| 89 | |||||
| 90 | <?php do_action( 'lsx_search_form_before' ); ?> |
||||
| 91 | |||||
| 92 | <nav class="navbar navbar-light bg-light"> |
||||
| 93 | |||||
| 94 | <form class="<?php echo esc_attr( $classes ); ?>" action="<?php echo esc_attr( $action ); ?>" method="<?php echo esc_attr( $method ); ?>"> |
||||
| 95 | |||||
| 96 | <?php do_action( 'lsx_search_form_top' ); ?> |
||||
| 97 | |||||
| 98 | <div class="input-group navbar-nav"> |
||||
| 99 | <?php if ( true === $display_search_field ) : ?> |
||||
|
0 ignored issues
–
show
|
|||||
| 100 | <div class="field"> |
||||
| 101 | <input class="search-field form-control" name="s" type="search" placeholder="<?php echo esc_attr( $placeholder ); ?>" autocomplete="off"> |
||||
| 102 | </div> |
||||
| 103 | <?php endif; ?> |
||||
| 104 | |||||
| 105 | <?php if ( false !== $engine_select && false !== $engine && 'default' !== $engine ) : |
||||
|
0 ignored issues
–
show
|
|||||
| 106 | $engines = explode( '|',$engine ); ?> |
||||
|
0 ignored issues
–
show
|
|||||
| 107 | <div class="field engine-select"> |
||||
| 108 | <div class="dropdown nav-item"> |
||||
| 109 | <?php |
||||
| 110 | $plural = 's'; |
||||
| 111 | if ( 'accommodation' === $engine[0] ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 112 | $plural = ''; |
||||
| 113 | } |
||||
| 114 | ?> |
||||
| 115 | <button id="engine" data-selection="<?php echo esc_attr( $engines[0] ); ?>" class="btn border-btn btn-dropdown dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo esc_html( ucwords( str_replace( '_', ' ',$engines[0] ) ) . $plural ); ?> <span class="caret"></span></button> |
||||
| 116 | <ul class="dropdown-menu"> |
||||
| 117 | <?php |
||||
| 118 | foreach ( $engines as $engine ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 119 | $plural = 's'; |
||||
| 120 | if ( 'accommodation' === $engine ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 121 | $plural = ''; |
||||
| 122 | } |
||||
| 123 | echo '<li><a data-value="' . esc_attr( $engine ) . '" href="#">' . esc_html( ucfirst( str_replace( '_', ' ',$engine ) ) . $plural ) . '</a></li>'; |
||||
| 124 | } |
||||
| 125 | ?> |
||||
| 126 | </ul> |
||||
| 127 | </div> |
||||
| 128 | </div> |
||||
| 129 | <?php endif; ?> |
||||
| 130 | |||||
| 131 | <?php if ( false !== $facets ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 132 | $facets = explode( '|',$facets ); |
||||
| 133 | |||||
| 134 | if ( ! is_array( $facets ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 135 | $facets = array( $facets ); |
||||
| 136 | } |
||||
| 137 | |||||
| 138 | $field_class = 'field'; |
||||
| 139 | |||||
| 140 | if ( false !== $combo_box ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 141 | $this->combo_box( $facets ); |
||||
| 142 | $field_class .= ' combination-toggle hidden'; |
||||
| 143 | } |
||||
| 144 | |||||
| 145 | foreach ( $facets as $facet ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 146 | ?> |
||||
| 147 | <div class="<?php echo wp_kses_post( $field_class ); ?>"> |
||||
| 148 | <?php |
||||
| 149 | $facet = FWP()->helper->get_facet_by_name( $facet ); |
||||
|
0 ignored issues
–
show
The function
FWP was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 150 | if ( isset( $facet['source'] ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 151 | $values = $this->get_form_facet( $facet['source'] ); |
||||
| 152 | } else { |
||||
| 153 | $values = array(); |
||||
| 154 | } |
||||
| 155 | $facet_display_type = apply_filters( 'lsx_search_form_field_type', 'select', $facet ); |
||||
| 156 | $this->display_form_field( $facet_display_type,$facet,$values,$combo_box ); |
||||
| 157 | ?> |
||||
| 158 | </div> |
||||
| 159 | <?php |
||||
| 160 | } |
||||
| 161 | } ?> |
||||
|
0 ignored issues
–
show
|
|||||
| 162 | |||||
| 163 | <div class="field submit-button"> |
||||
| 164 | <button class="<?php echo esc_attr( $button_class ); ?>" type="submit"><?php echo wp_kses_post( $button_label ); ?></button> |
||||
| 165 | </div> |
||||
| 166 | |||||
| 167 | <?php if ( false === $engine_select && false !== $engine && 'default' !== $engine ) : ?> |
||||
|
0 ignored issues
–
show
|
|||||
| 168 | <input name="engine" type="hidden" value="<?php echo esc_attr( $engine ); ?>"> |
||||
| 169 | <?php endif; ?> |
||||
| 170 | </div> |
||||
| 171 | |||||
| 172 | <?php do_action( 'lsx_search_form_bottom' ); ?> |
||||
| 173 | |||||
| 174 | </form> |
||||
| 175 | |||||
| 176 | </nav> |
||||
| 177 | |||||
| 178 | <?php do_action( 'lsx_search_form_after' ); ?> |
||||
| 179 | <?php |
||||
| 180 | $return = ob_get_clean(); |
||||
| 181 | |||||
| 182 | $return = preg_replace( '/[\n]+/', ' ', $return ); |
||||
| 183 | $return = preg_replace( '/[\t]+/', ' ', $return ); |
||||
| 184 | |||||
| 185 | return $return; |
||||
| 186 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 187 | |||||
| 188 | /** |
||||
| 189 | * Outputs the combination selector |
||||
| 190 | */ |
||||
| 191 | public function combo_box( $facets ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 192 | ?> |
||||
| 193 | <div class="field combination-dropdown"> |
||||
| 194 | <div class="dropdown"> |
||||
| 195 | <button data-selection="0" class="btn border-btn btn-dropdown dropdown-toggle btn-combination" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> |
||||
| 196 | <?php esc_attr_e( 'Select', 'lsx-search' ); ?> |
||||
| 197 | <span class="caret"></span> |
||||
| 198 | </button> |
||||
| 199 | <ul class="dropdown-menu"> |
||||
| 200 | |||||
| 201 | <li style="display: none;"><a class="default" data-value="0" href="#"><?php esc_attr_e( 'Select ', 'lsx-search' ); ?></a></li> |
||||
| 202 | |||||
| 203 | <?php foreach ( $facets as $facet ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 204 | $facet = FWP()->helper->get_facet_by_name( $facet ); |
||||
|
0 ignored issues
–
show
The function
FWP was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 205 | ?> |
||||
| 206 | <li><a data-value="fwp_<?php echo wp_kses_post( $facet['name'] ); ?>" href="#"><?php echo wp_kses_post( $facet['label'] ); ?></a></li> |
||||
| 207 | <?php } ?> |
||||
| 208 | </ul> |
||||
| 209 | </div> |
||||
| 210 | </div> |
||||
| 211 | <?php |
||||
| 212 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 213 | |||||
| 214 | /** |
||||
| 215 | * Grabs the Values for the Facet in Question. |
||||
| 216 | */ |
||||
| 217 | protected function get_form_facet( $facet_source = false ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 218 | global $wpdb; |
||||
| 219 | |||||
| 220 | $values = array(); |
||||
| 221 | $select = 'f.facet_value, f.facet_display_value'; |
||||
| 222 | $from = "{$wpdb->prefix}facetwp_index f"; |
||||
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||||
| 223 | $where = "f.facet_source = '{$facet_source}'"; |
||||
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||||
| 224 | |||||
| 225 | //Check if the current facet is showing destinations. |
||||
| 226 | if ( stripos( $facet_source, 'destination_to' ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 227 | $from .= " INNER JOIN {$wpdb->posts} p ON f.facet_value = p.ID"; |
||||
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||||
| 228 | $where .= " AND p.post_parent = '0'"; |
||||
| 229 | |||||
|
0 ignored issues
–
show
|
|||||
| 230 | } |
||||
| 231 | |||||
| 232 | $response = $wpdb->prepare( "SELECT {$select} FROM {$from} WHERE {$where}" );// WPCS: unprepared SQL OK. |
||||
|
0 ignored issues
–
show
|
|||||
| 233 | |||||
| 234 | if ( ! empty( $response ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 235 | foreach ( $response as $re ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 236 | $display_value = $re->facet_display_value; |
||||
| 237 | if ( function_exists( 'pll_translate_string' ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 238 | $current_lang = pll_current_language(); |
||||
|
0 ignored issues
–
show
The function
pll_current_language was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||||
| 239 | $display_value = pll_translate_string( $display_value, $current_lang ); |
||||
| 240 | } |
||||
| 241 | $display_value = apply_filters( 'lsx_search_facetwp_display_value', $display_value, $re->facet_value ); |
||||
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||||
| 242 | $values[ $re->facet_value ] = $display_value; |
||||
| 243 | } |
||||
| 244 | } |
||||
| 245 | |||||
| 246 | asort( $values ); |
||||
| 247 | return $values; |
||||
| 248 | } |
||||
|
0 ignored issues
–
show
|
|||||
| 249 | |||||
| 250 | /** |
||||
| 251 | * Change FaceWP pagination HTML to be equal main pagination (WP-PageNavi) |
||||
| 252 | */ |
||||
| 253 | public function display_form_field( $type = 'select', $facet = array(), $values = array(), $combo = false ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 254 | if ( empty( $facet ) ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 255 | return; |
||||
| 256 | } |
||||
| 257 | |||||
| 258 | $source = 'fwp_' . $facet['name']; |
||||
| 259 | |||||
| 260 | switch ( $type ) { |
||||
|
0 ignored issues
–
show
|
|||||
| 261 | |||||
| 262 | case 'select': ?> |
||||
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. Loading history...
|
|||||
| 263 | <div class="dropdown nav-item <?php if ( true === $combo ) { echo 'combination-dropdown'; } ?>"> |
||||
|
0 ignored issues
–
show
|
|||||
| 264 | <button data-selection="0" class="btn border-btn btn-dropdown dropdown-toggle" type="button" id="<?php echo wp_kses_post( $source ); ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> |
||||
| 265 | <?php echo esc_attr( apply_filters( 'lsx_search_facet_label', __( 'Select', 'lsx-search' ) . ' ' . wp_kses_post( $facet['label'] ) ) ); ?> |
||||
| 266 | <span class="caret"></span> |
||||
| 267 | </button> |
||||
| 268 | <ul class="dropdown-menu" aria-labelledby="<?php echo wp_kses_post( $source ); ?>"> |
||||
| 269 | <?php if ( ! empty( $values ) ) { ?> |
||||
|
0 ignored issues
–
show
|
|||||
| 270 | |||||
| 271 | <li style="display: none;"> |
||||
| 272 | <a class="default" data-value="0" href="#"> |
||||
| 273 | <?php |
||||
| 274 | $facet_label = __( 'Select ', 'lsx-search' ) . ' ' . wp_kses_post( $facet['label'] ); |
||||
| 275 | $facet_label = apply_filters( 'lsx_search_facet_label', $facet_label ); |
||||
| 276 | echo esc_attr( $facet_label ); |
||||
| 277 | ?> |
||||
| 278 | </a> |
||||
| 279 | </li> |
||||
| 280 | |||||
| 281 | <?php foreach ( $values as $key => $value ) { ?> |
||||
|
0 ignored issues
–
show
|
|||||
| 282 | <li><a data-value="<?php echo wp_kses_post( $key ); ?>" href="#"><?php echo wp_kses_post( $value ); ?></a></li> |
||||
| 283 | <?php } ?> |
||||
| 284 | <?php } else { ?> |
||||
| 285 | <li><a data-value="0" href="#"><?php esc_attr_e( 'Please re-index your facets.', 'lsx-search' ); ?></a></li> |
||||
| 286 | <?php } ?> |
||||
| 287 | </ul> |
||||
| 288 | </div> |
||||
| 289 | <?php |
||||
| 290 | break; |
||||
| 291 | |||||
| 292 | case 'datepicker': ?> |
||||
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. Loading history...
|
|||||
| 293 | <div class="datepicker nav-item"> |
||||
| 294 | <input autocomplete="off" class="datepicker-value" placeholder="<?php echo wp_kses_post( apply_filters( 'lsx_search_facet_label' , $facet['label'] ) ); ?>" name="<?php echo wp_kses_post( $source ); ?>" id="<?php echo wp_kses_post( $source ); ?>" type="text" value="" /> |
||||
|
0 ignored issues
–
show
|
|||||
| 295 | </div> |
||||
| 296 | <?php |
||||
| 297 | break; |
||||
| 298 | } |
||||
| 299 | |||||
| 300 | ?> |
||||
| 301 | |||||
| 302 | <?php } |
||||
|
0 ignored issues
–
show
|
|||||
| 303 | } |
||||
| 304 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.