| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
/** |
| 6 |
* WPSight_General class |
| 7 |
*/ |
| 8 |
class WPSight_General { |
| 9 |
|
| 10 |
/** |
| 11 |
* Constructor |
| 12 |
*/ |
| 13 |
public function __construct( ) { |
| 14 |
add_filter( 'wpsight_details', array( $this, 'check_standard_details' ), 20 ); |
| 15 |
add_filter( 'wpsight_rental_periods', array( $this, 'check_rental_periods' ), 20 ); |
| 16 |
add_filter( 'init', array( $this, 'listing_query_vars_general' ) ); |
| 17 |
add_filter( 'init', array( $this, 'listing_query_vars_details' ) ); |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* details() |
| 22 |
* |
| 23 |
* Function that defines the array |
| 24 |
* of standard listing details (beds, baths etc.) |
| 25 |
* |
| 26 |
* @uses wpsight_sort_array_by_position() |
| 27 |
* @return array $details Array of standard listing details |
| 28 |
* |
| 29 |
* @since 1.0.0 |
| 30 |
*/ |
| 31 |
public static function details() { |
| 32 |
|
| 33 |
// Set standard details |
| 34 |
|
| 35 |
$details = array( |
| 36 |
|
| 37 |
'details_1' => array( |
| 38 |
'id' => 'details_1', |
| 39 |
'label' => __( 'Beds', 'wpcasa' ), |
| 40 |
'unit' => '', |
| 41 |
'data' => array( '' => __( 'n/d', 'wpcasa' ), '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10' ), |
| 42 |
'description' => '', |
| 43 |
'query_var' => 'bedrooms', |
| 44 |
'data_compare' => '>=', |
| 45 |
'data_type' => 'numeric', |
| 46 |
'dashboard' => true, |
| 47 |
'position' => 10 |
| 48 |
), |
| 49 |
'details_2' => array( |
| 50 |
'id' => 'details_2', |
| 51 |
'label' => __( 'Baths', 'wpcasa' ), |
| 52 |
'unit' => '', |
| 53 |
'data' => array( '' => __( 'n/d', 'wpcasa' ), '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10' ), |
| 54 |
'description' => '', |
| 55 |
'query_var' => 'bathrooms', |
| 56 |
'data_compare' => '>=', |
| 57 |
'data_type' => 'numeric', |
| 58 |
'dashboard' => true, |
| 59 |
'position' => 20 |
| 60 |
), |
| 61 |
'details_3' => array( |
| 62 |
'id' => 'details_3', |
| 63 |
'label' => __( 'Plot Size', 'wpcasa' ), |
| 64 |
'unit' => 'm2', |
| 65 |
'description' => '', |
| 66 |
'query_var' => 'plot_size', |
| 67 |
'data_compare' => '>=', |
| 68 |
'data_type' => 'numeric', |
| 69 |
'dashboard' => true, |
| 70 |
'position' => 30 |
| 71 |
), |
| 72 |
'details_4' => array( |
| 73 |
'id' => 'details_4', |
| 74 |
'label' => __( 'Living Area', 'wpcasa' ), |
| 75 |
'unit' => 'm2', |
| 76 |
'data' => false, |
| 77 |
'description' => '', |
| 78 |
'query_var' => 'living_area', |
| 79 |
'data_compare' => '>=', |
| 80 |
'data_type' => 'numeric', |
| 81 |
'dashboard' => true, |
| 82 |
'position' => 40 |
| 83 |
), |
| 84 |
'details_5' => array( |
| 85 |
'id' => 'details_5', |
| 86 |
'label' => __( 'Terrace', 'wpcasa' ), |
| 87 |
'unit' => 'm2', |
| 88 |
'data' => false, |
| 89 |
'description' => '', |
| 90 |
'query_var' => 'terrace', |
| 91 |
'data_compare' => 'LIKE', |
| 92 |
'data_type' => 'CHAR', |
| 93 |
'dashboard' => true, |
| 94 |
'position' => 50 |
| 95 |
), |
| 96 |
'details_6' => array( |
| 97 |
'id' => 'details_6', |
| 98 |
'label' => __( 'Parking', 'wpcasa' ), |
| 99 |
'unit' => '', |
| 100 |
'data' => false, |
| 101 |
'description' => '', |
| 102 |
'query_var' => 'parking', |
| 103 |
'data_compare' => 'LIKE', |
| 104 |
'data_type' => 'CHAR', |
| 105 |
'dashboard' => true, |
| 106 |
'position' => 60 |
| 107 |
), |
| 108 |
'details_7' => array( |
| 109 |
'id' => 'details_7', |
| 110 |
'label' => __( 'Heating', 'wpcasa' ), |
| 111 |
'unit' => '', |
| 112 |
'data' => false, |
| 113 |
'description' => '', |
| 114 |
'query_var' => 'heating', |
| 115 |
'data_compare' => 'LIKE', |
| 116 |
'data_type' => 'CHAR', |
| 117 |
'dashboard' => true, |
| 118 |
'position' => 70 |
| 119 |
), |
| 120 |
'details_8' => array( |
| 121 |
'id' => 'details_8', |
| 122 |
'label' => __( 'Built in', 'wpcasa' ), |
| 123 |
'unit' => '', |
| 124 |
'data' => false, |
| 125 |
'description' => '', |
| 126 |
'query_var' => 'built_in', |
| 127 |
'data_compare' => 'LIKE', |
| 128 |
'data_type' => 'CHAR', |
| 129 |
'dashboard' => true, |
| 130 |
'position' => 80 |
| 131 |
) |
| 132 |
|
| 133 |
); |
| 134 |
|
| 135 |
// Apply filter to array |
| 136 |
$details = apply_filters( 'wpsight_details', $details ); |
| 137 |
|
| 138 |
// Sort array by position |
| 139 |
$details = wpsight_sort_array_by_position( $details ); |
| 140 |
|
| 141 |
// Return array |
| 142 |
return $details; |
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* check_standard_details() |
| 148 |
* |
| 149 |
* Filter standard details and update if |
| 150 |
* label and/or unit have been set on options page |
| 151 |
* |
| 152 |
* @uses wpsight_get_option() |
| 153 |
* @return array Updated standard details |
| 154 |
* |
| 155 |
* @since 1.0.0 |
| 156 |
*/ |
| 157 |
public static function check_standard_details( $standard_details ) { |
| 158 |
|
| 159 |
// Just return originals on reset |
| 160 |
|
| 161 |
if ( isset( $_POST['reset'] ) ) |
| 162 |
return $standard_details; |
| 163 |
|
| 164 |
// Loop through details and check against database |
| 165 |
|
| 166 |
foreach ( $standard_details as $detail => $value ) { |
| 167 |
|
| 168 |
$standard_details_option = (array) wpsight_get_option( $detail, $value ); |
| 169 |
|
| 170 |
if ( ! empty( $standard_details_option ) ) { |
| 171 |
$standard_details[ $detail ]['label'] = $standard_details_option['label'] ?? ''; |
| 172 |
$standard_details[ $detail ]['unit'] = $standard_details_option['unit'] ?? ''; |
| 173 |
} |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
return $standard_details; |
| 178 |
|
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* get_detail() |
| 183 |
* |
| 184 |
* Get specific detail. |
| 185 |
* |
| 186 |
* @param string $detail Key of the detail to return |
| 187 |
* @param bool $return Only return specific element of detail array |
| 188 |
* @uses self::details() |
| 189 |
* @return array|string|bool |
| 190 |
* |
| 191 |
* @since 1.0.0 |
| 192 |
*/ |
| 193 |
public static function get_detail( $detail, $return = false ) { |
| 194 |
|
| 195 |
// Get available details |
| 196 |
$details = self::details(); |
| 197 |
|
| 198 |
// Return array of specific detail |
| 199 |
|
| 200 |
if ( $return === false ) |
| 201 |
return $details[ $detail ]; |
| 202 |
|
| 203 |
// Only return specific detail element |
| 204 |
|
| 205 |
if ( isset( $details[ $detail ][ $return ] ) ) |
| 206 |
return $details[ $detail ][ $return ]; |
| 207 |
|
| 208 |
return false; |
| 209 |
|
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* get_detail_by_query_var() |
| 214 |
* |
| 215 |
* Get specific detail by it's query var key |
| 216 |
* in the wpsight_details() array. |
| 217 |
* |
| 218 |
* @param string $query_var query_var key |
| 219 |
* @uses self::details() |
| 220 |
* @return string Key of the detail array element |
| 221 |
* |
| 222 |
* @since 1.0.0 |
| 223 |
*/ |
| 224 |
public static function get_detail_by_query_var( $query_var ) { |
| 225 |
|
| 226 |
// Get available details |
| 227 |
$details = self::details(); |
| 228 |
|
| 229 |
// Get query vars |
| 230 |
$query_vars = wp_list_pluck( $details, 'query_var' ); |
| 231 |
|
| 232 |
// Check if query var in array |
| 233 |
$result = array_search( $query_var, $query_vars ); |
| 234 |
|
| 235 |
// If no query var set, use array key |
| 236 |
|
| 237 |
if ( $result === false && isset( $query_vars[ $query_var ] ) ) |
| 238 |
return $query_var; |
| 239 |
|
| 240 |
return $result; |
| 241 |
|
| 242 |
} |
| 243 |
|
| 244 |
/** |
| 245 |
* get_query_var_by_detail() |
| 246 |
* |
| 247 |
* Get specific detail by it's query var key |
| 248 |
* in the wpsight_details() array. |
| 249 |
* |
| 250 |
* @param string $query_var query_var key |
| 251 |
* @uses self::details() |
| 252 |
* @uses wp_list_pluck() |
| 253 |
* @return string Key of the detail array element |
| 254 |
* |
| 255 |
* @since 1.0.0 |
| 256 |
*/ |
| 257 |
public static function get_query_var_by_detail( $detail ) { |
| 258 |
|
| 259 |
// Get available details |
| 260 |
$details = self::details(); |
| 261 |
|
| 262 |
// Get query vars |
| 263 |
$detail_vars = wp_list_pluck( $details, 'query_var' ); |
| 264 |
|
| 265 |
// Check if query var in array |
| 266 |
|
| 267 |
if ( isset( $detail_vars[ $detail ] ) && $detail_vars[ $detail ] !== false ) |
| 268 |
return $detail_vars[ $detail ]; |
| 269 |
|
| 270 |
return $detail; |
| 271 |
|
| 272 |
} |
| 273 |
|
| 274 |
/** |
| 275 |
* offers() |
| 276 |
* |
| 277 |
* Function that defines the array |
| 278 |
* of available listing offers (sale, rent etc.) |
| 279 |
* |
| 280 |
* @return array |
| 281 |
* |
| 282 |
* @since 1.0.0 |
| 283 |
*/ |
| 284 |
public static function offers() { |
| 285 |
|
| 286 |
$offers = array( |
| 287 |
'sale' => __( 'For Sale', 'wpcasa' ), |
| 288 |
'rent' => __( 'For Rent', 'wpcasa' ) |
| 289 |
); |
| 290 |
|
| 291 |
return apply_filters( 'wpsight_offers', $offers ); |
| 292 |
|
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* get_offer() |
| 297 |
* |
| 298 |
* Get specific offer. |
| 299 |
* |
| 300 |
* @param string $offer Key of the offer to return |
| 301 |
* @uses self::offers() |
| 302 |
* @return string|bool Label of the offer or false if offer does not exist |
| 303 |
* |
| 304 |
* @since 1.0.0 |
| 305 |
*/ |
| 306 |
public static function get_offer( $offer ) { |
| 307 |
|
| 308 |
// Get available offers |
| 309 |
$offers = self::offers(); |
| 310 |
|
| 311 |
// Return label of specific offer |
| 312 |
|
| 313 |
if ( isset( $offers[ $offer ] ) ) |
| 314 |
return $offers[ $offer ]; |
| 315 |
|
| 316 |
return false; |
| 317 |
|
| 318 |
} |
| 319 |
|
| 320 |
/** |
| 321 |
* get_offer_color() |
| 322 |
* |
| 323 |
* Get specific offer color used for labels etc. |
| 324 |
* |
| 325 |
* @param string $offer Key of the offer to return |
| 326 |
* @return string|bool Color of the offer or false if offer does not exist |
| 327 |
* |
| 328 |
* @since 1.0.0 |
| 329 |
*/ |
| 330 |
public static function get_offer_color( $offer ) { |
| 331 |
|
| 332 |
// Set offer colors |
| 333 |
|
| 334 |
$colors = array( |
| 335 |
'sale' => '#27ae60', |
| 336 |
'rent' => '#2980b9' |
| 337 |
); |
| 338 |
|
| 339 |
// Apply filter |
| 340 |
$colors = apply_filters( 'wpsight_offer_colors', $colors ); |
| 341 |
|
| 342 |
// Set color of specific offer |
| 343 |
$color = isset( $colors[ $offer ] ) ? $colors[ $offer ] : false; |
| 344 |
|
| 345 |
return apply_filters( 'wpsight_get_offer_color', $color ); |
| 346 |
|
| 347 |
} |
| 348 |
|
| 349 |
/** |
| 350 |
* rental_periods() |
| 351 |
* |
| 352 |
* Function that defines the array |
| 353 |
* of available rental periods (monthly etc.) |
| 354 |
* |
| 355 |
* @return array |
| 356 |
* |
| 357 |
* @since 1.0.0 |
| 358 |
*/ |
| 359 |
public static function rental_periods() { |
| 360 |
|
| 361 |
$rental_periods = array( |
| 362 |
|
| 363 |
'rental_period_1' => __( 'per Month', 'wpcasa' ), |
| 364 |
'rental_period_2' => __( 'per Week', 'wpcasa' ), |
| 365 |
'rental_period_3' => __( 'per Year', 'wpcasa' ), |
| 366 |
'rental_period_4' => __( 'per Day', 'wpcasa' ) |
| 367 |
|
| 368 |
); |
| 369 |
|
| 370 |
return apply_filters( 'wpsight_rental_periods', $rental_periods ); |
| 371 |
|
| 372 |
} |
| 373 |
|
| 374 |
/** |
| 375 |
* check_rental_periods() |
| 376 |
* |
| 377 |
* Filter rental periods and update if |
| 378 |
* label has been set on options page |
| 379 |
* |
| 380 |
* @uses wpsight_get_option() |
| 381 |
* @return array Updated rental periods |
| 382 |
* |
| 383 |
* @since 1.0.0 |
| 384 |
*/ |
| 385 |
public static function check_rental_periods( $rental_periods ) { |
| 386 |
|
| 387 |
// Just return originals on reset |
| 388 |
|
| 389 |
if ( isset( $_POST['reset'] ) ) |
| 390 |
return $rental_periods; |
| 391 |
|
| 392 |
// Loop through details and check against database |
| 393 |
|
| 394 |
foreach ( $rental_periods as $period => $value ) { |
| 395 |
|
| 396 |
$rental_periods_option = wpsight_get_option( $period ); |
| 397 |
|
| 398 |
if( ! empty( $rental_periods_option ) ) |
| 399 |
$rental_periods[ $period ] = $rental_periods_option; |
| 400 |
|
| 401 |
} |
| 402 |
|
| 403 |
return $rental_periods; |
| 404 |
|
| 405 |
} |
| 406 |
|
| 407 |
/** |
| 408 |
* get_rental_period() |
| 409 |
* |
| 410 |
* Get specific rental period. |
| 411 |
* |
| 412 |
* @param string $period Key of the period to return |
| 413 |
* @uses self::rental_periods() |
| 414 |
* @return string|bool Label of the period or false if period does not exist |
| 415 |
* |
| 416 |
* @since 1.0.0 |
| 417 |
*/ |
| 418 |
public static function get_rental_period( $period ) { |
| 419 |
|
| 420 |
// Get available periods |
| 421 |
$rental_periods = self::rental_periods(); |
| 422 |
|
| 423 |
// Return label of specific period |
| 424 |
|
| 425 |
if ( isset( $rental_periods[ $period ] ) ) |
| 426 |
return $rental_periods[ $period ]; |
| 427 |
|
| 428 |
return false; |
| 429 |
|
| 430 |
} |
| 431 |
|
| 432 |
/** |
| 433 |
* measurements() |
| 434 |
* |
| 435 |
* Function that defines the array |
| 436 |
* of available measurement units (m2, etc.) |
| 437 |
* |
| 438 |
* @return array |
| 439 |
* |
| 440 |
* @since 1.0.0 |
| 441 |
*/ |
| 442 |
public static function measurements() { |
| 443 |
|
| 444 |
$measurements = array( |
| 445 |
'' => '', |
| 446 |
'm2' => 'm²', |
| 447 |
'sqft' => 'sq ft', |
| 448 |
'sqyd' => 'sq yd', |
| 449 |
'acres' => 'acre(s)' |
| 450 |
); |
| 451 |
|
| 452 |
return apply_filters( 'wpsight_measurements', $measurements ); |
| 453 |
|
| 454 |
} |
| 455 |
|
| 456 |
/** |
| 457 |
* get_measurement() |
| 458 |
* |
| 459 |
* Get specific measurement unit. |
| 460 |
* |
| 461 |
* @param string $measurement Key of the measurement to return |
| 462 |
* @uses self::measurements() |
| 463 |
* @return string|bool Label of the measurement or false if unit does not exist |
| 464 |
* |
| 465 |
* @since 1.0.0 |
| 466 |
*/ |
| 467 |
public static function get_measurement( $measurement ) { |
| 468 |
|
| 469 |
// Get available measurements |
| 470 |
$measurements = self::measurements(); |
| 471 |
|
| 472 |
// Return label of specific measurement |
| 473 |
|
| 474 |
if ( isset( $measurements[ $measurement ] ) ) |
| 475 |
return $measurements[ $measurement ]; |
| 476 |
|
| 477 |
return false; |
| 478 |
|
| 479 |
} |
| 480 |
|
| 481 |
/** |
| 482 |
* date_formats() |
| 483 |
* |
| 484 |
* Function that defines the array |
| 485 |
* of available date formats. |
| 486 |
* |
| 487 |
* @return array |
| 488 |
* |
| 489 |
* @since 1.0.0 |
| 490 |
*/ |
| 491 |
public static function date_formats( $date_i18n = false ) { |
| 492 |
|
| 493 |
$formats = apply_filters( 'date_formats', array( 'F j, Y', 'j. F Y', 'Y-m-d', 'y-m-d', 'm/d/Y', 'm/d/y', 'd/m/Y', 'd/m/y', 'd.m.Y', 'd.m.y' ) ); |
| 494 |
|
| 495 |
$date_formats = array(); |
| 496 |
|
| 497 |
foreach ( $formats as $format ) |
| 498 |
$date_formats[ $format ] = $date_i18n === true ? date_i18n( $format ) : $format; |
| 499 |
|
| 500 |
return array_unique( apply_filters( 'wpsight_date_formats', $date_formats ) ); |
| 501 |
|
| 502 |
} |
| 503 |
|
| 504 |
/** |
| 505 |
* statuses() |
| 506 |
* |
| 507 |
* Function that defines the array |
| 508 |
* of available post statuses |
| 509 |
* |
| 510 |
* @return array |
| 511 |
* |
| 512 |
* @since 1.0.0 |
| 513 |
*/ |
| 514 |
public static function statuses() { |
| 515 |
|
| 516 |
$statuses = array( |
| 517 |
|
| 518 |
'draft' => array( |
| 519 |
'name' => _x( 'Draft', 'listing post status', 'wpcasa' ), |
| 520 |
'label' => _x( 'Draft', 'listing post status', 'wpcasa' ) |
| 521 |
), |
| 522 |
'publish' => array( |
| 523 |
'name' => _x( 'Active', 'listing post status', 'wpcasa' ), |
| 524 |
'label' => _x( 'Active', 'listing post status', 'wpcasa' ) |
| 525 |
), |
| 526 |
'pending' => array( |
| 527 |
'name' => _x( 'Pending', 'listing post status', 'wpcasa' ), |
| 528 |
'label' => _x( 'Pending approval', 'listing post status', 'wpcasa' ) |
| 529 |
), |
| 530 |
'preview' => array( |
| 531 |
'name' => _x( 'Preview', 'listing post status', 'wpcasa' ), |
| 532 |
'label' => _x( 'Preview', 'listing post status', 'wpcasa' ), |
| 533 |
'public' => false, |
| 534 |
'exclude_from_search' => true, |
| 535 |
'show_in_admin_all_list' => false, |
| 536 |
'show_in_admin_status_list' => false, |
| 537 |
// Translators: %s is listing name |
| 538 |
'label_count' => _n_noop( 'Preview <span class="count">(%s)</span>', 'Previews <span class="count">(%s)</span>', 'wpcasa' ) |
| 539 |
), |
| 540 |
'pending_payment' => array( |
| 541 |
'name' => _x( 'Pending', 'listing post status', 'wpcasa' ), |
| 542 |
'label' => _x( 'Pending payment', 'listing post status', 'wpcasa' ), |
| 543 |
'public' => true, |
| 544 |
'exclude_from_search' => true, |
| 545 |
'show_in_admin_all_list' => true, |
| 546 |
'show_in_admin_status_list' => true, |
| 547 |
// Translators: %s is listing name which payment is pending |
| 548 |
'label_count' => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payments <span class="count">(%s)</span>', 'wpcasa' ) |
| 549 |
), |
| 550 |
'trash' => array( |
| 551 |
'name' => _x( 'Trash', 'listing post status', 'wpcasa' ), |
| 552 |
'label' => _x( 'Trash', 'listing post status', 'wpcasa' ) |
| 553 |
) |
| 554 |
|
| 555 |
); |
| 556 |
|
| 557 |
return apply_filters( 'wpsight_statuses', $statuses ); |
| 558 |
|
| 559 |
} |
| 560 |
|
| 561 |
/** |
| 562 |
* get_status() |
| 563 |
* |
| 564 |
* Get specific listing status |
| 565 |
* |
| 566 |
* @param string $status Key of the corresponding status |
| 567 |
* @param string $field Field of the status (default: label) |
| 568 |
* @uses self::statuses() |
| 569 |
* @return array |
| 570 |
* |
| 571 |
* @since 1.0.0 |
| 572 |
*/ |
| 573 |
public static function get_status( $status, $field = 'label' ) { |
| 574 |
|
| 575 |
// Get all available statuses |
| 576 |
$statuses = self::statuses(); |
| 577 |
|
| 578 |
if ( isset( $statuses[ $status ][ $field ] ) ) |
| 579 |
return $statuses[ $status ][ $field ]; |
| 580 |
|
| 581 |
return false; |
| 582 |
|
| 583 |
} |
| 584 |
|
| 585 |
/** |
| 586 |
* currencies() |
| 587 |
* |
| 588 |
* Function that defines the array |
| 589 |
* of available currencies (USD, EUR etc.) |
| 590 |
* |
| 591 |
* @return array |
| 592 |
* |
| 593 |
* @since 1.0.0 |
| 594 |
*/ |
| 595 |
public static function currencies() { |
| 596 |
|
| 597 |
$currencies = array( |
| 598 |
'aed' => __( 'AED => United Arab Emirates Dirham', 'wpcasa' ), |
| 599 |
'ang' => __( 'ANG => Netherlands Antillean Guilder', 'wpcasa' ), |
| 600 |
'ars' => __( 'ARS => Argentine Peso', 'wpcasa' ), |
| 601 |
'aud' => __( 'AUD => Australian Dollar', 'wpcasa' ), |
| 602 |
'bdt' => __( 'BDT => Bangladeshi Taka', 'wpcasa' ), |
| 603 |
'bgn' => __( 'BGN => Bulgarian Lev', 'wpcasa' ), |
| 604 |
'bhd' => __( 'BHD => Bahraini Dinar', 'wpcasa' ), |
| 605 |
'bnd' => __( 'BND => Brunei Dollar', 'wpcasa' ), |
| 606 |
'bob' => __( 'BOB => Bolivian Boliviano', 'wpcasa' ), |
| 607 |
'brl' => __( 'BRL => Brazilian Real', 'wpcasa' ), |
| 608 |
'bwp' => __( 'BWP => Botswanan Pula', 'wpcasa' ), |
| 609 |
'cad' => __( 'CAD => Canadian Dollar', 'wpcasa' ), |
| 610 |
'chf_sfr' => __( 'CHF => Swiss Franc (SFr.)', 'wpcasa' ), |
| 611 |
'chf' => __( 'CHF => Swiss Franc (CHF)', 'wpcasa' ), |
| 612 |
'clp' => __( 'CLP => Chilean Peso', 'wpcasa' ), |
| 613 |
'cny' => __( 'CNY => Chinese Yuan', 'wpcasa' ), |
| 614 |
'cop' => __( 'COP => Colombian Peso', 'wpcasa' ), |
| 615 |
'crc' => __( 'CRC => Costa Rican Colon', 'wpcasa' ), |
| 616 |
'czk' => __( 'CZK => Czech Republic Koruna', 'wpcasa' ), |
| 617 |
'dkk' => __( 'DKK => Danish Krone', 'wpcasa' ), |
| 618 |
'dop' => __( 'DOP => Dominican Peso', 'wpcasa' ), |
| 619 |
'dzd' => __( 'DZD => Algerian Dinar', 'wpcasa' ), |
| 620 |
'eek' => __( 'EEK => Estonian Kroon', 'wpcasa' ), |
| 621 |
'egp' => __( 'EGP => Egyptian Pound', 'wpcasa' ), |
| 622 |
'eur' => __( 'EUR => Euro', 'wpcasa' ), |
| 623 |
'fjd' => __( 'FJD => Fijian Dollar', 'wpcasa' ), |
| 624 |
'gbp' => __( 'GBP => British Pound', 'wpcasa' ), |
| 625 |
'hkd' => __( 'HKD => Hong Kong Dollar', 'wpcasa' ), |
| 626 |
'hnl' => __( 'HNL => Honduran Lempira', 'wpcasa' ), |
| 627 |
'hrk' => __( 'HRK => Croatian Kuna', 'wpcasa' ), |
| 628 |
'huf' => __( 'HUF => Hungarian Forint', 'wpcasa' ), |
| 629 |
'idr' => __( 'IDR => Indonesian Rupiah', 'wpcasa' ), |
| 630 |
'ils' => __( 'ILS => Israeli New Sheqel', 'wpcasa' ), |
| 631 |
'inr' => __( 'INR => Indian Rupee', 'wpcasa' ), |
| 632 |
'jmd' => __( 'JMD => Jamaican Dollar', 'wpcasa' ), |
| 633 |
'jod' => __( 'JOD => Jordanian Dinar', 'wpcasa' ), |
| 634 |
'jpy' => __( 'JPY => Japanese Yen', 'wpcasa' ), |
| 635 |
'kes' => __( 'KES => Kenyan Shilling', 'wpcasa' ), |
| 636 |
'krw' => __( 'KRW => South Korean Won', 'wpcasa' ), |
| 637 |
'kwd' => __( 'KWD => Kuwaiti Dinar', 'wpcasa' ), |
| 638 |
'kyd' => __( 'KYD => Cayman Islands Dollar', 'wpcasa' ), |
| 639 |
'kzt' => __( 'KZT => Kazakhstani Tenge', 'wpcasa' ), |
| 640 |
'lbp' => __( 'LBP => Lebanese Pound', 'wpcasa' ), |
| 641 |
'lkr' => __( 'LKR => Sri Lankan Rupee', 'wpcasa' ), |
| 642 |
'ltl' => __( 'LTL => Lithuanian Litas', 'wpcasa' ), |
| 643 |
'lvl' => __( 'LVL => Latvian Lats', 'wpcasa' ), |
| 644 |
'mad' => __( 'MAD => Moroccan Dirham', 'wpcasa' ), |
| 645 |
'mdl' => __( 'MDL => Moldovan Leu', 'wpcasa' ), |
| 646 |
'mkd' => __( 'MKD => Macedonian Denar', 'wpcasa' ), |
| 647 |
'mur' => __( 'MUR => Mauritian Rupee', 'wpcasa' ), |
| 648 |
'mvr' => __( 'MVR => Maldivian Rufiyaa', 'wpcasa' ), |
| 649 |
'mxn' => __( 'MXN => Mexican Peso', 'wpcasa' ), |
| 650 |
'myr' => __( 'MYR => Malaysian Ringgit', 'wpcasa' ), |
| 651 |
'nad' => __( 'NAD => Namibian Dollar', 'wpcasa' ), |
| 652 |
'ngn' => __( 'NGN => Nigerian Naira', 'wpcasa' ), |
| 653 |
'nio' => __( 'NIO => Nicaraguan Cordoba', 'wpcasa' ), |
| 654 |
'nok' => __( 'NOK => Norwegian Krone', 'wpcasa' ), |
| 655 |
'npr' => __( 'NPR => Nepalese Rupee', 'wpcasa' ), |
| 656 |
'nzd' => __( 'NZD => New Zealand Dollar', 'wpcasa' ), |
| 657 |
'omr' => __( 'OMR => Omani Rial', 'wpcasa' ), |
| 658 |
'pen' => __( 'PEN => Peruvian Nuevo Sol', 'wpcasa' ), |
| 659 |
'pgk' => __( 'PGK => Papua New Guinean Kina', 'wpcasa' ), |
| 660 |
'php' => __( 'PHP => Philippine Peso', 'wpcasa' ), |
| 661 |
'pkr' => __( 'PKR => Pakistani Rupee', 'wpcasa' ), |
| 662 |
'pln' => __( 'PLN => Polish Zloty', 'wpcasa' ), |
| 663 |
'pyg' => __( 'PYG => Paraguayan Guarani', 'wpcasa' ), |
| 664 |
'qar' => __( 'QAR => Qatari Rial', 'wpcasa' ), |
| 665 |
'ron' => __( 'RON => Romanian Leu', 'wpcasa' ), |
| 666 |
'rsd' => __( 'RSD => Serbian Dinar', 'wpcasa' ), |
| 667 |
'rub' => __( 'RUB => Russian Ruble', 'wpcasa' ), |
| 668 |
'sar' => __( 'SAR => Saudi Riyal', 'wpcasa' ), |
| 669 |
'scr' => __( 'SCR => Seychellois Rupee', 'wpcasa' ), |
| 670 |
'sek' => __( 'SEK => Swedish Krona', 'wpcasa' ), |
| 671 |
'sgd' => __( 'SGD => Singapore Dollar', 'wpcasa' ), |
| 672 |
'skk' => __( 'SKK => Slovak Koruna', 'wpcasa' ), |
| 673 |
'sll' => __( 'SLL => Sierra Leonean Leone', 'wpcasa' ), |
| 674 |
'svc' => __( 'SVC => Salvadoran Colon', 'wpcasa' ), |
| 675 |
'thb' => __( 'THB => Thai Baht', 'wpcasa' ), |
| 676 |
'tnd' => __( 'TND => Tunisian Dinar', 'wpcasa' ), |
| 677 |
'try' => __( 'TRY => Turkish Lira', 'wpcasa' ), |
| 678 |
'ttd' => __( 'TTD => Trinidad and Tobago Dollar', 'wpcasa' ), |
| 679 |
'twd' => __( 'TWD => New Taiwan Dollar', 'wpcasa' ), |
| 680 |
'tzs' => __( 'TZS => Tanzanian Shilling', 'wpcasa' ), |
| 681 |
'uah' => __( 'UAH => Ukrainian Hryvnia', 'wpcasa' ), |
| 682 |
'ugx' => __( 'UGX => Ugandan Shilling', 'wpcasa' ), |
| 683 |
'usd' => __( 'USD => US Dollar', 'wpcasa' ), |
| 684 |
'uyu' => __( 'UYU => Uruguayan Peso', 'wpcasa' ), |
| 685 |
'uzs' => __( 'UZS => Uzbekistan Som', 'wpcasa' ), |
| 686 |
'vef' => __( 'VEF => Venezuelan Bolivar', 'wpcasa' ), |
| 687 |
'vnd' => __( 'VND => Vietnamese Dong', 'wpcasa' ), |
| 688 |
'xof' => __( 'XOF => CFA Franc BCEAO', 'wpcasa' ), |
| 689 |
'yer' => __( 'YER => Yemeni Rial', 'wpcasa' ), |
| 690 |
'zar' => __( 'ZAR => South African Rand', 'wpcasa' ), |
| 691 |
'zmk' => __( 'ZMK => Zambian Kwacha', 'wpcasa' ) |
| 692 |
); |
| 693 |
|
| 694 |
return apply_filters( 'wpsight_currencies', $currencies ); |
| 695 |
|
| 696 |
} |
| 697 |
|
| 698 |
/** |
| 699 |
* get_currency_abbr() |
| 700 |
* |
| 701 |
* Get 3-letter currency abbreviation. |
| 702 |
* |
| 703 |
* @param string $currency 3-letter code of specific currency |
| 704 |
* @uses wpsight_get_option() |
| 705 |
* @return string 3-letter currency code |
| 706 |
* |
| 707 |
* @since 1.0.0 |
| 708 |
*/ |
| 709 |
public static function get_currency_abbr( $currency = '' ) { |
| 710 |
|
| 711 |
if ( empty( $currency ) ) |
| 712 |
$currency = wpsight_get_option( 'currency', 'eur' ); |
| 713 |
|
| 714 |
// Check if there is a custom currency |
| 715 |
|
| 716 |
if ( $currency != 'other' ) { |
| 717 |
|
| 718 |
return strtoupper( $currency ); |
| 719 |
|
| 720 |
} else { |
| 721 |
|
| 722 |
return wpsight_get_option( 'currency_other' ); |
| 723 |
|
| 724 |
} |
| 725 |
|
| 726 |
} |
| 727 |
|
| 728 |
/** |
| 729 |
* get_currency() |
| 730 |
* |
| 731 |
* Get currency entity. |
| 732 |
* |
| 733 |
* @param string $currency 3-letter code of specific currency |
| 734 |
* @uses wpsight_get_option() |
| 735 |
* @uses wpsight_get_currency_abbr() |
| 736 |
* @return string Currency entity or 3-letter code |
| 737 |
* |
| 738 |
* @since 1.0.0 |
| 739 |
*/ |
| 740 |
public static function get_currency( $currency = '' ) { |
| 741 |
|
| 742 |
// Get currency from theme options |
| 743 |
|
| 744 |
if ( empty( $currency ) ) |
| 745 |
$currency = wpsight_get_option( 'currency', 'eur' ); |
| 746 |
|
| 747 |
// Check if there is a custom currency |
| 748 |
|
| 749 |
if ( $currency != 'other' ) { |
| 750 |
|
| 751 |
// Get currency abbreviation |
| 752 |
|
| 753 |
$currency = wpsight_get_currency_abbr( $currency ); |
| 754 |
|
| 755 |
// Create HTML entities |
| 756 |
|
| 757 |
if ( $currency == 'EUR' ) { |
| 758 |
$currency_ent = '€'; |
| 759 |
} |
| 760 |
elseif ( $currency == 'USD' ) { |
| 761 |
$currency_ent = '$'; |
| 762 |
} |
| 763 |
elseif ( $currency == 'CAD' ) { |
| 764 |
$currency_ent = 'C$'; |
| 765 |
} |
| 766 |
elseif ( $currency == 'GBP' ) { |
| 767 |
$currency_ent = '£'; |
| 768 |
} |
| 769 |
elseif ( $currency == 'AUD' ) { |
| 770 |
$currency_ent = 'AU$'; |
| 771 |
} |
| 772 |
elseif ( $currency == 'JPY' ) { |
| 773 |
$currency_ent = '¥'; |
| 774 |
} |
| 775 |
elseif ( $currency == 'CHF_SFR' ) { |
| 776 |
$currency_ent = ' SFr. '; |
| 777 |
} |
| 778 |
elseif ( $currency == 'ILS' ) { |
| 779 |
$currency_ent = '₪'; |
| 780 |
} |
| 781 |
elseif ( $currency == 'THB' ) { |
| 782 |
$currency_ent = '฿'; |
| 783 |
} |
| 784 |
elseif ( $currency == 'BRL' ) { |
| 785 |
$currency_ent = 'R$'; |
| 786 |
} |
| 787 |
|
| 788 |
} else { |
| 789 |
|
| 790 |
$currency_ent = wpsight_get_option( 'currency_other_ent' ); |
| 791 |
|
| 792 |
} |
| 793 |
|
| 794 |
// If no entity, set three letter code |
| 795 |
|
| 796 |
if ( empty( $currency_ent ) ) |
| 797 |
$currency_ent = ' ' . $currency . ' '; |
| 798 |
|
| 799 |
return apply_filters( 'wpsight_get_currency', $currency_ent, $currency ); |
| 800 |
|
| 801 |
} |
| 802 |
|
| 803 |
/** |
| 804 |
* currency() |
| 805 |
* |
| 806 |
* Echo wpsight_get_currency(). |
| 807 |
* |
| 808 |
* @param string $currency 3-letter code of specific currency |
| 809 |
* @return string Currency entity or 3-letter code |
| 810 |
* @uses wpsight_get_currency() |
| 811 |
* |
| 812 |
* @since 1.0.0 |
| 813 |
*/ |
| 814 |
public static function currency( $currency = '' ) { |
| 815 |
echo esc_html( wpsight_get_currency( $currency ) ); |
| 816 |
} |
| 817 |
|
| 818 |
/** |
| 819 |
* spaces() |
| 820 |
* |
| 821 |
* Function that defines the array |
| 822 |
* of available widget spaces. |
| 823 |
* |
| 824 |
* @uses wpsight_post_type() |
| 825 |
* @return array |
| 826 |
* |
| 827 |
* @since 1.0.0 |
| 828 |
*/ |
| 829 |
public static function spaces() { |
| 830 |
|
| 831 |
/** |
| 832 |
* Spaces are empty by default but can |
| 833 |
* be create using the wpsight_spaces |
| 834 |
* filter hook in add-ons or themes. |
| 835 |
*/ |
| 836 |
return apply_filters( 'wpsight_spaces', array() ); |
| 837 |
|
| 838 |
} |
| 839 |
|
| 840 |
/** |
| 841 |
* listing_query_vars() |
| 842 |
* |
| 843 |
* Rreturn all custom query vars for listings |
| 844 |
* |
| 845 |
* @uses self::listing_query_vars_general() |
| 846 |
* @uses self::listing_query_vars_details() |
| 847 |
* @uses self::listing_query_vars_taxonomies() |
| 848 |
* @return array |
| 849 |
* |
| 850 |
* @since 1.0.0 |
| 851 |
*/ |
| 852 |
public static function listing_query_vars() { |
| 853 |
|
| 854 |
$vars = array_merge( |
| 855 |
(array) self::listing_query_vars_general(), |
| 856 |
(array) self::listing_query_vars_details(), |
| 857 |
(array) self::listing_query_vars_taxonomies() |
| 858 |
); |
| 859 |
|
| 860 |
return apply_filters( 'wpsight_listing_query_vars', $vars ); |
| 861 |
|
| 862 |
} |
| 863 |
|
| 864 |
/** |
| 865 |
* listing_query_vars_general() |
| 866 |
* |
| 867 |
* Add general query vars for listings |
| 868 |
* |
| 869 |
* @uses get_query_var() |
| 870 |
* @uses add_query_var() |
| 871 |
* @return array |
| 872 |
* |
| 873 |
* @since 1.0.0 |
| 874 |
*/ |
| 875 |
public static function listing_query_vars_general() { |
| 876 |
global $wp; |
| 877 |
|
| 878 |
// Set custom vars |
| 879 |
|
| 880 |
$vars = array( |
| 881 |
'keyword' => get_query_var( 'keyword' ), |
| 882 |
'status' => get_query_var( 'status' ), |
| 883 |
'offer' => get_query_var( 'offer' ), |
| 884 |
'min' => get_query_var( 'min' ), |
| 885 |
'max' => get_query_var( 'max' ), |
| 886 |
'nr' => get_query_var( 'nr' ) |
| 887 |
); |
| 888 |
|
| 889 |
// Add query vars |
| 890 |
|
| 891 |
foreach ( array_keys( $vars ) as $var ) |
| 892 |
$wp->add_query_var( $var ); |
| 893 |
|
| 894 |
return $vars; |
| 895 |
|
| 896 |
} |
| 897 |
|
| 898 |
/** |
| 899 |
* listing_query_vars_details() |
| 900 |
* |
| 901 |
* Add detail query vars for listings |
| 902 |
* |
| 903 |
* @uses self::details() |
| 904 |
* @uses wpsight_get_query_var_by_detail() |
| 905 |
* @uses get_query_var() |
| 906 |
* @uses add_query_var() |
| 907 |
* @return array |
| 908 |
* |
| 909 |
* @since 1.0.0 |
| 910 |
*/ |
| 911 |
public static function listing_query_vars_details() { |
| 912 |
global $wp; |
| 913 |
|
| 914 |
// Set custom vars |
| 915 |
$vars = array(); |
| 916 |
|
| 917 |
// Get all listing details |
| 918 |
$details = self::details(); |
| 919 |
|
| 920 |
// Loop through details |
| 921 |
|
| 922 |
foreach ( $details as $k => $v ) { |
| 923 |
|
| 924 |
$k = wpsight_get_query_var_by_detail( $k ); |
| 925 |
|
| 926 |
$vars[$k] = get_query_var( $k ); |
| 927 |
|
| 928 |
} |
| 929 |
|
| 930 |
foreach ( array_keys( $vars ) as $var ) |
| 931 |
$wp->add_query_var( $var ); |
| 932 |
|
| 933 |
return $vars; |
| 934 |
|
| 935 |
} |
| 936 |
|
| 937 |
/** |
| 938 |
* listing_query_vars_taxonomies() |
| 939 |
* |
| 940 |
* Return taxonomy query vars for listings |
| 941 |
* |
| 942 |
* @uses wpsight_post_type() |
| 943 |
* @uses wpsight_taxonomies() |
| 944 |
* @uses get_query_var() |
| 945 |
* @return array |
| 946 |
* |
| 947 |
* @since 1.0.0 |
| 948 |
*/ |
| 949 |
public static function listing_query_vars_taxonomies() { |
| 950 |
|
| 951 |
// Set custom vars |
| 952 |
$vars = array(); |
| 953 |
|
| 954 |
// Loop through taxonomies |
| 955 |
|
| 956 |
foreach ( wpsight_taxonomies( 'names' ) as $k ) |
| 957 |
$vars[$k] = get_query_var( $k ); |
| 958 |
|
| 959 |
return $vars; |
| 960 |
|
| 961 |
} |
| 962 |
|
| 963 |
} |
| 964 |
|