| 1 |
<?php |
| 2 |
/** |
| 3 |
* Show options for ordering |
| 4 |
* |
| 5 |
* @author PropertyHive |
| 6 |
* @package PropertyHive/Templates |
| 7 |
* @version 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 11 |
|
| 12 |
global $propertyhive; |
| 13 |
|
| 14 |
?> |
| 15 |
<form class="propertyhive-ordering" method="get"> |
| 16 |
<?php |
| 17 |
if ( |
| 18 |
( !in_array( $department, array('', 'commercial') ) && ph_get_custom_department_based_on($department) != 'commercial' ) || |
| 19 |
( $department == '' && get_option( 'propertyhive_primary_department' ) != 'commercial' && ph_get_custom_department_based_on(get_option( 'propertyhive_primary_department' )) != 'commercial' ) |
| 20 |
) |
| 21 |
{ |
| 22 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable; the template is included through a helper/function scope, so PrefixAllGlobals misclassifies the file when checked standalone. |
| 23 |
$results_orderby = apply_filters( 'propertyhive_results_orderby', array( |
| 24 |
'price-desc' => __( 'Default sorting', 'propertyhive' ), |
| 25 |
'date' => __( 'Sort by date added', 'propertyhive' ), |
| 26 |
'price-asc' => __( 'Sort by price: low to high', 'propertyhive' ), |
| 27 |
'price-desc' => __( 'Sort by price: high to low', 'propertyhive' ), |
| 28 |
) ); |
| 29 |
} |
| 30 |
else |
| 31 |
{ |
| 32 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable; the template is included through a helper/function scope, so PrefixAllGlobals misclassifies the file when checked standalone. |
| 33 |
$results_orderby = apply_filters( 'propertyhive_results_orderby', array( |
| 34 |
'floor_area-desc' => __( 'Default sorting', 'propertyhive' ), |
| 35 |
'date' => __( 'Sort by date added', 'propertyhive' ), |
| 36 |
'floor_area-asc' => __( 'Sort by floor area: low to high', 'propertyhive' ), |
| 37 |
'floor_area-desc' => __( 'Sort by floor area: high to low', 'propertyhive' ), |
| 38 |
'price-asc' => __( 'Sort by price: low to high', 'propertyhive' ), |
| 39 |
'price-desc' => __( 'Sort by price: high to low', 'propertyhive' ), |
| 40 |
) ); |
| 41 |
} |
| 42 |
|
| 43 |
if ( !empty($results_orderby) ) |
| 44 |
{ |
| 45 |
?> |
| 46 |
<select name="orderby" class="orderby"> |
| 47 |
<?php |
| 48 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable; the template is included through a helper/function scope, so PrefixAllGlobals misclassifies the file when checked standalone. |
| 49 |
foreach ( $results_orderby as $id => $name ) |
| 50 |
{ |
| 51 |
echo '<option value="' . esc_attr( $id ) . '" ' . selected( $orderby, $id, false ) . '>' . esc_attr( $name ) . '</option>'; |
| 52 |
} |
| 53 |
?> |
| 54 |
</select> |
| 55 |
<?php |
| 56 |
} |
| 57 |
|
| 58 |
// Keep query string vars intact |
| 59 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound, WordPress.Security.NonceVerification.Recommended -- Function-scoped template locals preserve read-only search filters; every hidden-field name/value is escaped below. |
| 60 |
foreach ( $_GET as $key => $val ) { |
| 61 |
if ( 'orderby' === $key || 'submit' === $key ) |
| 62 |
continue; |
| 63 |
|
| 64 |
if ( is_array( $val ) ) { |
| 65 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable; the template is included through a helper/function scope, so PrefixAllGlobals misclassifies the file when checked standalone. |
| 66 |
foreach( $val as $innerVal ) { |
| 67 |
echo '<input type="hidden" name="' . esc_attr( $key ) . '[]" value="' . esc_attr( $innerVal ) . '" />'; |
| 68 |
} |
| 69 |
|
| 70 |
} else { |
| 71 |
echo '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $val ) . '" />'; |
| 72 |
} |
| 73 |
} |
| 74 |
?> |
| 75 |
</form> |
| 76 |
|