1: <?php
2: /**
3: * Template Functions
4: *
5: * @package EPL
6: * @subpackage Functions/Templates
7: * @copyright Copyright (c) 2020, Merv Barrett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 1.0
10: */
11:
12: // Exit if accessed directly.
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: // phpcs:disable WordPress.NamingConventions.ValidVariableName
18: // phpcs:disable WordPress.Security.NonceVerification
19:
20: /**
21: * Property Object
22: *
23: * @param WP_Post $post Post object.
24: *
25: * @since 2.2
26: * @since 3.4.38 Support for third & fourth agents.
27: */
28: function epl_reset_property_object( $post ) {
29:
30: global $epl_author, $epl_author_secondary, $epl_author_third, $epl_author_fourth;
31:
32: if ( ! is_epl_post() ) {
33: return;
34: }
35:
36: global $property;
37: $property = new EPL_Property_Meta( $post );
38: $ID = epl_listing_has_primary_agent(); //phpcs:ignore
39: if ( $ID ) {
40: $epl_author = new EPL_Author_meta( $ID ); //phpcs:ignore
41:
42: } else {
43: $epl_author = new EPL_Author_meta( $post->post_author );
44: }
45:
46: $SEC_ID = epl_listing_has_secondary_author();
47:
48: if ( $SEC_ID ) {
49: $epl_author_secondary = new EPL_Author_meta( $SEC_ID );
50: }
51:
52: $third_ID = epl_listing_has_third_agent();
53:
54: if ( $third_ID ) {
55: $epl_author_third = new EPL_Author_meta( $third_ID );
56: }
57:
58: $fourth_ID = epl_listing_has_fourth_agent();
59:
60: if ( $fourth_ID ) {
61: $epl_author_fourth = new EPL_Author_meta( $fourth_ID );
62: }
63: }
64: add_action( 'the_post', 'epl_reset_property_object' );
65:
66: /**
67: * Make $property global available for hooks before the_post
68: *
69: * @since 2.2
70: * @since 3.5 Support for third & fourth agent.
71: */
72: function epl_create_property_object() {
73:
74: global $post, $property, $epl_author, $epl_author_secondary, $epl_author_third, $epl_author_fourth;
75:
76: if ( is_author() ) {
77: $author_id = get_query_var( 'author' );
78: $epl_author = new EPL_Author_meta( $author_id );
79: }
80: if ( is_null( $post ) ) {
81: return;
82: }
83: $epl_author = new EPL_Author_meta( $post->post_author );
84:
85: if ( is_epl_post() ) {
86: $property = new EPL_Property_Meta( $post );
87: $ID = epl_listing_has_secondary_author();
88: if ( $ID ) {
89: $epl_author_secondary = new EPL_Author_meta( $ID );
90: }
91: $third_ID = epl_listing_has_third_agent();
92:
93: if ( $third_ID ) {
94: $epl_author_third = new EPL_Author_meta( $third_ID );
95: }
96:
97: $fourth_ID = epl_listing_has_fourth_agent();
98:
99: if ( $fourth_ID ) {
100: $epl_author_fourth = new EPL_Author_meta( $fourth_ID );
101: }
102: }
103:
104: add_filter( 'excerpt_length', 'epl_archive_custom_excerpt_length', 999 );
105: }
106:
107: add_action( 'wp', 'epl_create_property_object' );
108:
109: /**
110: * Selecting Card Display Style
111: *
112: * @since 1.0
113: * @since 3.4.4 Removed default template check for single templates as this caused incorrect templates to load in some cases.
114: */
115: function epl_property_single() {
116: global $epl_settings;
117:
118: $action_check = has_action( 'epl_single_template' );
119: if ( ! empty( $action_check ) ) {
120: do_action( 'epl_single_template' );
121: } else {
122: epl_property_single_default();
123: }
124: }
125: add_action( 'epl_property_single', 'epl_property_single', 10, 1 );
126:
127: /**
128: * Featured Image template now loading through filter
129: *
130: * @param string $image_size The image size.
131: * @param string $image_class The image class.
132: * @param boolean $link The link.
133: *
134: * @since 1.2.0
135: * @since 3.4.8 Corrected missing parameter count to 3.
136: * @since 3.4.38 Added filter epl_property_featured_image_args to control all parameters & epl_no_property_featured_image action.
137: * @since 3.4.39 Added missing arguments variable to epl_no_property_featured_image action.
138: */
139: function epl_property_featured_image( $image_size = 'index_thumbnail', $image_class = 'index-thumbnail', $link = true ) {
140:
141: $args = apply_filters(
142: 'epl_property_featured_image_args',
143: array(
144: 'image_size' => $image_size,
145: 'image_class' => $image_class,
146: 'link' => $link,
147: )
148: );
149: /**
150: * Filter: Allow user or extension to enable or disable link behaviour on featured image.
151: */
152: $args['link'] = apply_filters( 'epl_property_featured_image_link', $args['link'] );
153:
154: if ( has_post_thumbnail() ) { ?>
155: <div class="entry-image">
156: <div class="epl-featured-image it-featured-image">
157: <?php if ( true === $args['link'] ) { ?>
158: <a href="<?php the_permalink(); ?>">
159: <?php } ?>
160: <?php the_post_thumbnail( $args['image_size'], array( 'class' => $args['image_class'] ) ); ?>
161: <?php if ( true === $args['link'] ) { ?>
162: </a>
163: <?php } ?>
164: </div>
165: </div>
166: <?php
167: } else {
168: do_action( 'epl_no_property_featured_image', $args );
169: }
170: }
171: add_action( 'epl_property_featured_image', 'epl_property_featured_image', 10, 3 );
172: add_action( 'epl_single_featured_image', 'epl_property_featured_image', 10, 3 );
173:
174: /**
175: * Featured Image on archive template now loading through filter
176: *
177: * @param string $image_size The image size.
178: * @param string $image_class The image class.
179: * @param bool $link Enable or disable the link with true/false. Default true.
180: * @param bool $stickers Enable or disable the stickers with true/false. Default true.
181: *
182: * @since 2.2
183: * @since 3.4.27 New: Additional param to disable / enable stickers
184: * @since 3.4.30 Fix: Missing parameter filter. Increased from 3 to 4.
185: * @since 3.4.38 Added filter epl_property_archive_featured_image to control all parameters & epl_no_archive_featured_image action if no featured image.
186: * @since 3.5.0 Replaced stickers html with an action hook epl_stickers_featured_image.
187: */
188: function epl_property_archive_featured_image( $image_size = 'epl-image-medium-crop', $image_class = 'teaser-left-thumb', $link = true, $stickers = true ) {
189:
190: if ( empty( $image_size ) ) {
191: $image_size = 'epl-image-medium-crop';
192: }
193:
194: $args = apply_filters(
195: 'epl_property_archive_featured_image_args',
196: array(
197: 'image_size' => $image_size,
198: 'image_class' => $image_class,
199: 'link' => $link,
200: 'stickers' => $stickers,
201: )
202: );
203: /**
204: * Filter: Allow user or extension to enable or disable link behaviour on archive image.
205: */
206: $args['link'] = apply_filters( 'epl_property_archive_featured_image_link', $args['link'] );
207:
208: if ( has_post_thumbnail() ) {
209: ?>
210: <div class="epl-archive-entry-image">
211: <?php if ( true === $args['link'] ) { ?>
212: <a href="<?php the_permalink(); ?>">
213: <?php } ?>
214: <div class="epl-blog-image">
215: <?php do_action( 'epl_stickers_featured_image', $args ); ?>
216: <?php the_post_thumbnail( $args['image_size'], array( 'class' => $args['image_class'] ) ); ?>
217: </div>
218: <?php if ( true === $args['link'] ) { ?>
219: </a>
220: <?php } ?>
221: </div>
222: <?php
223: } else {
224: do_action( 'epl_no_archive_featured_image', $args );
225: }
226: }
227: add_action( 'epl_property_archive_featured_image', 'epl_property_archive_featured_image', 10, 4 );
228:
229: /**
230: * Featured image sticker callback.
231: *
232: * @since 3.5.0
233: *
234: * @param array $args Arguments.
235: */
236: function epl_stickers_featured_image( $args ) {
237: if ( $args['stickers'] ) :
238: ?>
239: <div class="epl-stickers-wrapper">
240: <?php echo wp_kses_post( epl_get_price_sticker() ); ?>
241: </div>
242: <?php
243: endif;
244: }
245: add_action( 'epl_stickers_featured_image', 'epl_stickers_featured_image' );
246:
247: /**
248: * Featured Image in widgets
249: *
250: * @since 2.2
251: *
252: * @param string $image_size The image size.
253: * @param string $image_class The image class.
254: * @param boolean $link The link.
255: */
256: function epl_property_widgets_featured_image( $image_size = 'epl-image-medium-crop', $image_class = 'teaser-left-thumb', $link = true ) {
257:
258: if ( has_post_thumbnail() ) {
259: ?>
260: <div class="epl-archive-entry-image">
261: <?php if ( $link ) { ?>
262: <a href="<?php the_permalink(); ?>">
263: <?php } ?>
264: <div class="epl-blog-image">
265: <?php the_post_thumbnail( $image_size, array( 'class' => $image_class ) ); ?>
266: </div>
267: <?php if ( $link ) { ?>
268: </a>
269: <?php } ?>
270: </div>
271: <?php
272: }
273: }
274: add_action( 'epl_property_widgets_featured_image', 'epl_property_widgets_featured_image', 10, 3 );
275:
276: /**
277: * Single Listing Templates
278: *
279: * @since 1.0
280: */
281: function epl_property_single_default() {
282:
283: global $epl_settings;
284: if ( isset( $epl_settings['epl_feeling_lucky'] ) && 'on' === $epl_settings['epl_feeling_lucky'] ) {
285: epl_get_template_part( 'content-listing-single-compatibility.php' );
286: } else {
287: $single_tpl = 'content-listing-single.php';
288: $single_tpl = apply_filters( 'epl_property_single_default', $single_tpl );
289: epl_get_template_part( $single_tpl );
290: }
291: }
292:
293: /**
294: * Template Path
295: *
296: * @since 2.0
297: *
298: * @return string
299: */
300: function epl_get_content_path() {
301: return apply_filters( 'epl_templates_base_path', EPL_PATH_TEMPLATES_CONTENT );
302: }
303:
304: /**
305: * Template Fallback Path
306: *
307: * @return mixed|void
308: * @since 3.0
309: */
310: function epl_get_fallback_content_path() {
311: return apply_filters( 'epl_templates_fallback_base_path', EPL_PATH_TEMPLATES_CONTENT );
312: }
313:
314: /**
315: * Attempts to load templates in order of priority
316: *
317: * @param string $template Template name.
318: * @param array $arguments Options to pass to template.
319: * @param bool $default_template Pass a default template.
320: *
321: * @since 3.0
322: * @since 3.4.38 New: Additional parameter default_template to pass the default template which will be used if the template is not found.
323: * @since 3.4.41 Fix: Only the default template was loading.
324: * @since 3.5.3 Hook to filter find array as well as final template.
325: * @since 3.5.11 Pass the original template in the filter.
326: * @since 3.6 Security: refuses template names with ".." or a drive letter, so a shortcode attribute (wrap_template, template) can't include files outside the template folders.
327: */
328: function epl_get_template_part( $template, $arguments = array(), $default_template = false ) {
329:
330: // Template names are relative file names. Refuse "../" and drive paths.
331: if ( 0 !== validate_file( (string) $template ) || ( $default_template && 0 !== validate_file( (string) $default_template ) ) ) {
332: return;
333: }
334:
335: $original_template = $template;
336: $base_path = epl_get_content_path();
337: $default = $default_template ? $default_template : $template;
338: $find[] = epl_template_path() . $template;
339: $find = apply_filters( 'epl_template_part_find', $find, $template, $arguments, $default_template );
340: $template_location = locate_template( array_unique( $find ) );
341:
342: if ( ! $template_location ) {
343: $template = $base_path . $template;
344: $original_template = $template;
345: if ( ! file_exists( $template ) ) {
346: // Fallback to core.
347: $base_path = epl_get_fallback_content_path();
348: $template = $base_path . $default;
349: }
350: } else {
351: $template = $template_location;
352: }
353:
354: if ( ! isset( $arguments['epl_author'] ) ) {
355: global $epl_author;
356: }
357:
358: foreach ( $arguments as $key => $val ) {
359: ${$key} = $val;
360: }
361:
362: include apply_filters( 'epl_get_template_part', $template, $arguments, $default_template, $original_template );
363: }
364:
365: /**
366: * Modify the Excerpt length on Archive pages
367: *
368: * @since 1.0
369: * @since 3.4.27 Alter length only for EPL posts.
370: * @param string $length Excerpt word length.
371: * @return int|string
372: */
373: function epl_archive_custom_excerpt_length( $length ) {
374:
375: if ( ! is_epl_post() ) {
376: return $length;
377: }
378:
379: return epl_get_option( 'display_excerpt_length', 22 );
380: }
381:
382:
383: /**
384: * Filter which listing status should not be displayed
385: *
386: * @return mixed|void
387: * @since 3.1.20
388: * @since 3.4.45 Added deleted status.
389: */
390: function epl_hide_listing_statuses() {
391: return apply_filters( 'epl_hide_listing_statuses', array( 'withdrawn', 'offmarket', 'deleted' ) );
392: }
393:
394: /**
395: * Is this one of EPL's own listing queries on the front end?
396: *
397: * The listing archives, search results, location, feature and business category pages
398: * (the main query), the EPL shortcodes, the EPL widgets and Elementor Pro Loop Grids that use
399: * an EPL Loop Item. Admin screens, single listings and other plugins' queries (an importer
400: * looking up a listing, for example) are not.
401: *
402: * @param WP_Query $query The query.
403: *
404: * @return bool
405: *
406: * @since 3.6 Added.
407: */
408: function epl_is_front_end_listing_query( $query ) {
409: $is = false;
410:
411: if ( ! is_admin() && ! $query->is_singular() ) {
412: // EPL shortcodes and widgets, and Elementor Pro Loop Grids using an EPL Loop Item (Elementor draws those cards, so EPL's display check never runs).
413: $is = (bool) $query->get( 'is_epl_shortcode' ) || (bool) $query->get( 'is_epl_widget' ) || (bool) $query->get( 'epl_elementor_loop' );
414:
415: if ( ! $is && $query->is_main_query() ) {
416: $is = is_post_type_archive( epl_all_post_types() ) || is_tax( array( 'location', 'tax_feature', 'tax_business_listing' ) ) || epl_is_search();
417: }
418: }
419:
420: /**
421: * Filters whether a query is one of EPL's front end listing queries.
422: *
423: * @since 3.6
424: *
425: * @param bool $is True for EPL archives, search, shortcodes and widgets.
426: * @param WP_Query $query The query.
427: */
428: return (bool) apply_filters( 'epl_is_front_end_listing_query', $is, $query );
429: }
430:
431: /**
432: * Leave hidden listings (withdrawn, off market, deleted) out of EPL's listing queries
433: *
434: * Before 3.6 they were only skipped when each listing was shown, so pages showed fewer
435: * listings than they should, and page counts included listings nobody could see. Uses
436: * epl_hide_listing_statuses(), so a site that shows off market listings with that filter
437: * still gets them. Listings with no status are kept, as before.
438: *
439: * @param WP_Query $query The query.
440: *
441: * @return void
442: *
443: * @since 3.6 Added.
444: */
445: function epl_exclude_hidden_listing_statuses( $query ) {
446: if ( ! epl_is_front_end_listing_query( $query ) ) {
447: return;
448: }
449:
450: $hidden_ids = epl_get_hidden_listing_ids();
451: if ( empty( $hidden_ids ) ) {
452: return;
453: }
454:
455: $not_in = $query->get( 'post__not_in' );
456: $not_in = is_array( $not_in ) ? $not_in : array();
457:
458: $query->set( 'post__not_in', array_values( array_unique( array_merge( array_map( 'absint', $not_in ), $hidden_ids ) ) ) );
459: }
460: add_action( 'pre_get_posts', 'epl_exclude_hidden_listing_statuses', 20 );
461:
462: /**
463: * IDs of listings with a hidden status (epl_hide_listing_statuses())
464: *
465: * One query on the status meta key, kept in the listing query cache until a listing
466: * changes. Excluding these IDs is fast: a meta_query "status NOT IN, or no status" joins
467: * every meta row of every listing (15 seconds on 735 rentals, much longer at 100,000).
468: *
469: * @return int[]
470: *
471: * @since 3.6 Added.
472: */
473: function epl_get_hidden_listing_ids() {
474: global $wpdb;
475:
476: $hidden = array_values( array_filter( array_map( 'strval', (array) epl_hide_listing_statuses() ) ) );
477: if ( empty( $hidden ) ) {
478: return array();
479: }
480:
481: $placeholders = implode( ', ', array_fill( 0, count( $hidden ), '%s' ) );
482: $sql = $wpdb->prepare( "SELECT DISTINCT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'property_status' AND meta_value IN ( $placeholders )", $hidden ); // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
483:
484: return array_map( 'absint', epl_listing_query_cache( $sql ) );
485: }
486:
487: /**
488: * Selecting Card Display Style
489: *
490: * Allows the use of one function where we can then select a different template
491: * when needed
492: *
493: * @param string $template The template.
494: * @param string $default_value Optional template name.
495: *
496: * @since 1.0.0
497: * @since 3.4.4 Removed default template check for loop templates as this caused incorrect templates to load in some cases.
498: * @since 3.4.23 Removed compatibility template for loop as we are passing the class using post_class filter.
499: * @since 3.4.36 New: Additional action support for listing templates. Actions are: epl_loop_template_{post_type}, epl_loop_template_listing.
500: * @since 3.4.38 New: Additional parameters default to pass the default template which will be used if the template is not found.
501: * @since 3.5 New: Additional args for custom template action : epl_loop_template_{$post_type}, epl_loop_template.
502: */
503: function epl_property_blog( $template = '', $default_value = 'default' ) {
504:
505: if ( empty( $template ) || 'blog' === $template ) {
506: $template = 'default';
507: }
508: $template = str_replace( '_', '-', $template );
509:
510: global $epl_settings, $property;
511:
512: if ( is_null( $property ) ) {
513: return;
514: }
515:
516: $property_status = $property->get_property_meta( 'property_status' );
517: // Status Removal Do Not Display Withdrawn or OffMarket listings.
518: if ( ! in_array( $property_status, epl_hide_listing_statuses(), true ) ) {
519: // Do Not Display Withdrawn or OffMarket listings.
520:
521: $action_check_type = has_action( 'epl_loop_template_' . $property->post->post_type );
522: $action_check = has_action( 'epl_loop_template' );
523: $action_check_core = false;
524: $action_exists = false;
525:
526: if ( in_array( $property->post->post_type, epl_get_core_post_types(), true ) ) {
527: $action_check_core = has_action( 'epl_loop_template_listing' );
528: }
529:
530: // Check for action in order of priority : epl_loop_template_{post_type} > epl_loop_template_listing ( only for core ) > epl_loop_template.
531: if ( ! empty( $action_check_type ) ) {
532: do_action( 'epl_loop_template_' . $property->post->post_type, get_defined_vars() );
533: $action_exists = true;
534: } elseif ( ! empty( $action_check_core ) ) {
535: do_action( 'epl_loop_template_listing', get_defined_vars() );
536: $action_exists = true;
537: } elseif ( ! empty( $action_check ) ) {
538: do_action( 'epl_loop_template', get_defined_vars() );
539: $action_exists = true;
540: }
541:
542: // Fallback to core template.
543: if ( ! $action_exists ) {
544: $tpl_name = 'loop-listing-blog-' . $template . '.php';
545: $tpl_name = apply_filters( 'epl_property_blog_template', $tpl_name, get_defined_vars() );
546: epl_get_template_part( $tpl_name, array(), 'loop-listing-blog-' . $default_value . '.php' );
547: }
548: } // End Status Removal.
549: }
550: add_action( 'epl_property_blog', 'epl_property_blog', 10, 2 );
551:
552: /**
553: * Renders default author box
554: *
555: * @since 3.2
556: * @since 3.4.38 Support for third & fourth agent.
557: */
558: function epl_property_author_default() {
559: global $epl_author_secondary, $epl_author_third, $epl_author_fourth;
560: epl_get_template_part( 'content-author-box.php' );
561: if ( is_epl_post() ) {
562: if ( epl_listing_has_secondary_author() ) {
563: epl_get_template_part( 'content-author-box.php', array( 'epl_author' => $epl_author_secondary ) );
564: }
565: if ( epl_listing_has_third_agent() ) {
566: epl_get_template_part( 'content-author-box.php', array( 'epl_author' => $epl_author_third ) );
567: }
568: if ( epl_listing_has_fourth_agent() ) {
569: epl_get_template_part( 'content-author-box.php', array( 'epl_author' => $epl_author_fourth ) );
570: }
571: epl_reset_post_author();
572: }
573: }
574: /**
575: * AUTHOR CARD : Tabbed Style
576: *
577: * @since 1.0
578: */
579: function epl_property_author_box() {
580:
581: if ( has_action( 'epl_author_template' ) ) {
582: do_action( 'epl_author_template' );
583: } else {
584: epl_property_author_default();
585: }
586: }
587: add_action( 'epl_single_author', 'epl_property_author_box', 10 );
588:
589: /**
590: * Reset post author
591: *
592: * @since 1.0
593: */
594: function epl_reset_post_author() {
595: global $post, $epl_author;
596: if ( class_exists( 'EPL_Author_meta' ) ) {
597:
598: $ID = epl_listing_has_primary_agent();
599:
600: if ( is_epl_post() && $ID ) {
601: $epl_author = new EPL_Author_meta( $ID );
602: } else {
603: $epl_author = new EPL_Author_meta( $post->post_author );
604: }
605: }
606: }
607:
608: /**
609: * AUTHOR CARD : Standard
610: *
611: * @since 1.0
612: * @since 3.4.38 Support for third & fourth agent.
613: */
614: function epl_property_author_box_simple_card() {
615:
616: global $epl_author_secondary, $epl_author_third, $epl_author_fourth;
617: epl_get_template_part( 'content-author-box-simple-card.php' );
618: if ( is_epl_post() ) {
619: if ( epl_listing_has_secondary_author() ) {
620: epl_get_template_part( 'content-author-box-simple-card.php', array( 'epl_author' => $epl_author_secondary ) );
621: }
622: if ( epl_listing_has_third_agent() ) {
623: epl_get_template_part( 'content-author-box-simple-card.php', array( 'epl_author' => $epl_author_third ) );
624: }
625: if ( epl_listing_has_fourth_agent() ) {
626: epl_get_template_part( 'content-author-box-simple-card.php', array( 'epl_author' => $epl_author_fourth ) );
627: }
628: epl_reset_post_author();
629: }
630: }
631:
632: /**
633: * AUTHOR CARD : Gravatar
634: *
635: * @since 1.0
636: * @since 3.4.38 Support for third & fourth agent.
637: */
638: function epl_property_author_box_simple_grav() {
639:
640: global $epl_author_secondary, $epl_author_third, $epl_author_fourth;
641: epl_get_template_part( 'content-author-box-simple-grav.php' );
642: if ( is_epl_post() ) {
643: if ( epl_listing_has_secondary_author() ) {
644: epl_get_template_part( 'content-author-box-simple-grav.php', array( 'epl_author' => $epl_author_secondary ) );
645: }
646: if ( epl_listing_has_third_agent() ) {
647: epl_get_template_part( 'content-author-box-simple-grav.php', array( 'epl_author' => $epl_author_third ) );
648: }
649: if ( epl_listing_has_fourth_agent() ) {
650: epl_get_template_part( 'content-author-box-simple-grav.php', array( 'epl_author' => $epl_author_fourth ) );
651: }
652: epl_reset_post_author();
653: }
654: }
655:
656: /**
657: * WIDGET LISTING : Listing Card
658: *
659: * @param string $display The display.
660: * @param string $image The image.
661: * @param string $title The title.
662: * @param string $icons The icons.
663: * @param string $more_text The more text with epl_property_widget_read_more filter.
664: * @param string $d_excerpt The d excerpt.
665: * @param string $d_suburb The d suburb.
666: * @param string $d_street The d street.
667: * @param string $d_price The d price.
668: * @param string $d_more The d more.
669: * @param string $d_inspection_time The d inspection time.
670: * @param string $d_ical_link The d ical link.
671: *
672: * @since 1.0.0
673: * @since 3.4.13 for custom display, file extension not required and file name format enforced to the format widget-content-listing-{$display}.php
674: * @since 3.4.38 Support for third & fourth agent.
675: * @since 3.4.38 PHP 8.0 fix for parameter following optional parameter. Moved $more_text. Added epl_property_widget_read_more filter.
676: */
677: function epl_property_widget( $display, $image, $title, $icons, $more_text, $d_excerpt, $d_suburb, $d_street, $d_price, $d_more, $d_inspection_time, $d_ical_link ) {
678: global $property;
679:
680: if ( is_null( $property ) ) {
681: return;
682: }
683:
684: if ( empty( $more_text ) ) {
685: $more_text = apply_filters( 'epl_property_widget_read_more', __( 'Read More', 'easy-property-listings' ) );
686: }
687:
688: $property_status = $property->get_property_meta( 'property_status' );
689:
690: switch ( $display ) {
691: case 'list':
692: $tpl = 'widget-content-listing-list.php';
693: break;
694: case 'hide-image':
695: $tpl = 'widget-content-listing-hide-image.php';
696: break;
697: case 'image-only':
698: $tpl = 'widget-content-listing-image.php';
699: break;
700: case 'image':
701: $tpl = 'widget-content-listing.php';
702: break;
703: default:
704: $tpl = $display;
705: if ( ! epl_starts_with( $tpl, 'widget-content-listing' ) ) {
706: $tpl = 'widget-content-listing-' . $tpl;
707: }
708: if ( ! epl_ends_with( $tpl, '.php' ) ) {
709: $tpl .= '.php';
710: }
711: break;
712: }
713:
714: // Status Removal.
715: if ( ! in_array( $property_status, epl_hide_listing_statuses(), true ) ) {
716: // Do Not Display Withdrawn or OffMarket listings.
717: $arg_list = get_defined_vars();
718: if ( has_action( 'epl_listing_widget_template' ) ) {
719: do_action( 'epl_listing_widget_template', $tpl, $arg_list );
720: } else {
721: epl_get_template_part( $tpl, $arg_list );
722: }
723: } // End Status Removal.
724: }
725:
726: /**
727: * WIDGET LISTING : Listing List
728: *
729: * @since 1.0
730: */
731: function epl_property_widget_list_option() {
732: $property_status = get_post_meta( get_the_ID(), 'property_status', true );
733: // Status Removal.
734: if ( ! in_array( $property_status, epl_hide_listing_statuses(), true ) ) {
735: epl_get_template_part( 'widget-content-listing-list.php' );
736: }
737: }
738:
739: /**
740: * WIDGET LISTING : Image Only
741: *
742: * @since 1.0
743: *
744: * @param string $image The image.
745: */
746: function epl_property_widget_image_only_option( $image ) {
747: $property_status = get_post_meta( get_the_ID(), 'property_status', true );
748: // Status Removal.
749: if ( ! in_array( $property_status, epl_hide_listing_statuses(), true ) ) {
750: $arg_list = get_defined_vars();
751: }
752: epl_get_template_part( 'widget-content-listing-image.php', $arg_list );
753: }
754:
755:
756: /**
757: * WIDGET LISTING : Widget Tall Card
758: *
759: * @since 1.0
760: * @since 3.3 Revised.
761: *
762: * @param string $d_image The d image.
763: * @param string $d_icons The d icons.
764: * @param string $d_bio The d bio.
765: * @param string $username The username.
766: */
767: function epl_property_author_box_simple_card_tall( $d_image, $d_icons, $d_bio, $username ) {
768:
769: if ( ! empty( $username ) ) {
770: epl_show_author_widget_by_username( $d_image, $d_icons, $d_bio, $username );
771: return;
772: }
773:
774: global $property, $epl_author, $epl_author_secondary, $epl_author_third, $epl_author_fourth;
775: if ( is_null( $epl_author ) ) {
776: return;
777: }
778:
779: $arg_list = get_defined_vars();
780: epl_get_template_part( 'widget-content-author-tall.php', $arg_list );
781:
782: // Second Author.
783: if ( is_single() && ! is_null( $property ) ) {
784:
785: if ( is_epl_post() ) {
786: if ( epl_listing_has_secondary_author() ) {
787: $epl_author = $epl_author_secondary;
788: epl_get_template_part( 'widget-content-author-tall.php', $arg_list );
789: }
790: if ( epl_listing_has_third_agent() ) {
791: $epl_author = $epl_author_third;
792: epl_get_template_part( 'widget-content-author-tall.php', $arg_list );
793: }
794: if ( epl_listing_has_fourth_agent() ) {
795: $epl_author = $epl_author_fourth;
796: epl_get_template_part( 'widget-content-author-tall.php', $arg_list );
797: }
798: epl_reset_post_author();
799: }
800: }
801: }
802:
803: /**
804: * Display widget by username
805: *
806: * @since 3.3
807: *
808: * @param string $d_image The d image.
809: * @param string $d_icons The d icons.
810: * @param string $d_bio The d bio.
811: * @param string $username The username.
812: */
813: function epl_show_author_widget_by_username( $d_image, $d_icons, $d_bio, $username ) {
814: $username = explode( ',', $username );
815: $username = array_filter( $username );
816: foreach ( $username as $uname ) {
817: $author = get_user_by( 'login', sanitize_user( $uname ) );
818: if ( false !== $author ) {
819: $epl_author = new EPL_Author_meta( $author->ID );
820: $arg_list = get_defined_vars();
821: epl_get_template_part( 'widget-content-author-tall.php', $arg_list );
822: }
823: }
824: }
825:
826: /**
827: * Get the full address
828: *
829: * @return string The full address of the listing.
830: *
831: * @since 1.0.0
832: */
833: function epl_property_get_the_full_address() {
834: global $property;
835:
836: $address = '';
837: $sub_num = $property->get_property_meta( 'property_address_sub_number' );
838: if ( ! empty( $sub_num ) ) {
839: $address .= $property->get_property_meta( 'property_address_sub_number' ) . '/';
840: }
841: $address .= $property->get_property_meta( 'property_address_street_number' ) . ' ';
842: $address .= $property->get_property_meta( 'property_address_street' ) . ' ';
843: $address .= $property->get_property_meta( 'property_address_suburb' ) . ' ';
844: $address .= $property->get_property_meta( 'property_address_city' ) . ', ';
845: $address .= $property->get_property_meta( 'property_address_state' ) . ' ';
846: $address .= $property->get_property_meta( 'property_address_postal_code' ) . ' ';
847: $address .= $property->get_property_meta( 'property_address_country' );
848:
849: return $address;
850: }
851:
852: /**
853: * Get the full address
854: *
855: * @hooked epl_property_title
856: * @hooked property_tab_address
857: *
858: * @param bool $full Set to false too only display the street address.
859: * @param bool $street_separator Display the street separator.
860: * @param string $separator_symbol Symbol to use as the street separator, default is a comma.
861: *
862: * @since 1.0
863: * @since 3.3.3 Revised.
864: * @since 3.4.8 Corrected separator location to appear AFTER the street name and options to control display.
865: * @since 3.4.9 Added option allowing passing of $full parameter as false to restrict output to street items only.
866: * @since 3.5.14 Corrected escaping function to esc_html.
867: * @since 3.6 Uses the listing's address rules (show_street_address(), show_suburb(), show_address_city(), show_address_country()). Fix: commercial land listings now hide the suburb when Display Street Address and Display Suburb are both unticked, as commercial and business listings do.
868: */
869: function epl_property_the_address( $full = true, $street_separator = true, $separator_symbol = ',' ) {
870:
871: global $property, $epl_settings;
872:
873: if ( ! is_bool( $full ) ) {
874: $full = true;
875: }
876:
877: $epl_property_address_separator = apply_filters( 'epl_property_address_separator', ',' );
878: $epl_property_address_separator_suburb = apply_filters( 'epl_property_address_separator_suburb', false );
879: $epl_property_address_separator_city = apply_filters( 'epl_property_address_separator_city', false );
880:
881: ?>
882: <?php if ( $property->show_street_address() ) { ?>
883: <span class="item-street"><?php echo wp_kses_post( $property->get_formatted_property_address( $street_separator, $separator_symbol ) ); ?></span>
884: <?php } ?>
885:
886: <?php
887: if ( true === $full ) {
888: ?>
889: <span class="entry-title-sub">
890: <?php
891: if ( $property->show_suburb() ) {
892: ?>
893: <span class="item-suburb"><?php echo esc_html( $property->get_property_meta( 'property_address_suburb' ) ); ?></span>
894: <?php
895: if ( true === $epl_property_address_separator_suburb && strlen( trim( $property->get_property_meta( 'property_address_suburb' ) ) ) ) {
896: echo '<span class="item-separator">' . esc_html( $epl_property_address_separator ) . '</span>';
897: }
898: }
899: ?>
900:
901: <?php
902: if ( $property->show_address_city() ) {
903: ?>
904: <span class="item-city"><?php echo esc_html( $property->get_property_meta( 'property_address_city' ) ); ?></span>
905: <?php
906: if ( true === $epl_property_address_separator_city && strlen( trim( $property->get_property_meta( 'property_address_city' ) ) ) ) {
907: echo '<span class="item-separator">' . esc_html( $epl_property_address_separator ) . '</span>';
908: }
909: }
910: ?>
911: <span class="item-state"><?php echo esc_html( $property->get_property_meta( 'property_address_state' ) ); ?></span>
912: <span class="item-pcode"><?php echo esc_html( $property->get_property_meta( 'property_address_postal_code' ) ); ?></span>
913: <?php
914: if ( $property->show_address_country() ) {
915: ?>
916: <span class="item-country"><?php echo esc_html( $property->get_property_meta( 'property_address_country' ) ); ?></span>
917: <?php
918: }
919: ?>
920: </span>
921: <?php
922: }
923: }
924: add_action( 'epl_property_title', 'epl_property_the_address', 10, 3 );
925: add_action( 'epl_property_tab_address', 'epl_property_the_address', 10, 3 );
926: add_action( 'epl_property_address', 'epl_property_the_address', 10, 3 );
927:
928: /**
929: * Suburb Name Kept for listing templates extensions which use this function
930: *
931: * Shows the suburb, or the city, state and postcode when the listing hides its suburb.
932: *
933: * @since 1.3
934: * @since 3.1.18 Revised.
935: * @since 3.5.14 Corrected escaping function to esc_html.
936: * @since 3.6 Uses the listing's show_suburb() rule. Fix: a commercial or business listing showing its street address now shows its suburb even when Display Suburb is unticked, and commercial land listings follow Display Suburb, the same as epl_property_the_address().
937: */
938: function epl_property_suburb() {
939: global $property;
940:
941: if ( $property->show_suburb() ) {
942: ?>
943: <span class="entry-title-sub">
944: <span class="item-suburb"><?php echo esc_html( $property->get_property_meta( 'property_address_suburb' ) ); ?></span>
945: </span>
946: <?php
947: } else {
948: ?>
949:
950: <span class="entry-title-sub">
951: <?php $prop_addr_city = $property->get_property_meta( 'property_address_city' ); ?>
952: <?php if ( ! empty( $prop_addr_city ) ) { ?>
953: <span class="item-city"><?php echo esc_html( $property->get_property_meta( 'property_address_city' ) ) . ' '; ?></span>
954: <?php } ?>
955:
956: <span class="item-state"><?php echo esc_html( $property->get_property_meta( 'property_address_state' ) ) . ' '; ?></span>
957: <span class="item-pcode"><?php echo esc_html( $property->get_property_meta( 'property_address_postal_code' ) ); ?></span>
958: </span>
959:
960: <?php
961: }
962: }
963: add_action( 'epl_property_suburb', 'epl_property_suburb' );
964:
965: /**
966: * Get the price
967: *
968: * @since 1.0 @hooked property_price
969: * @hooked property_price_content
970: */
971: function epl_property_price() {
972: echo wp_kses_post( epl_get_property_price() );
973: }
974: add_action( 'epl_property_price', 'epl_property_price' );
975: add_action( 'epl_property_price_content', 'epl_property_price' );
976:
977: /**
978: * Get Property icons
979: *
980: * @param array $args The arguments.
981: * @param string $returntype The returntype.
982: *
983: * @return false|string
984: *
985: * @since 1.0
986: * @since 3.3.3 Added switch.
987: */
988: function epl_get_property_icons( $args = array(), $returntype = 'i' ) {
989:
990: global $property;
991:
992: $defaults = array( 'bed', 'bath', 'parking', 'ac', 'pool' );
993:
994: $icons = apply_filters( 'epl_get_property_icons', $defaults );
995: $returntype = apply_filters( 'epl_icons_return_type', $returntype );
996:
997: ob_start();
998: //phpcs:disable
999: foreach ( $icons as $icon ) {
1000:
1001: if ( ! empty( $args ) && ! in_array( $icon, $args, true ) ) {
1002: continue;
1003: }
1004:
1005: switch ( $icon ) {
1006:
1007: case 'bed':
1008: echo $property->get_property_bed( $returntype );
1009: break;
1010:
1011: case 'bath':
1012: echo $property->get_property_bath( $returntype );
1013: break;
1014:
1015: case 'parking':
1016: echo $property->get_property_parking( $returntype );
1017: break;
1018:
1019: case 'ac':
1020: echo $property->get_property_air_conditioning( $returntype );
1021: break;
1022:
1023: case 'pool':
1024: echo $property->get_property_pool( $returntype );
1025: break;
1026:
1027: default:
1028: // Action to hook additional icons.
1029: do_action( 'epl_get_property_icon_' . $icon );
1030: break;
1031: }
1032: }
1033: //phpcs:enable
1034: return ob_get_clean();
1035: }
1036:
1037: /**
1038: * Property icons
1039: *
1040: * @param string $returntype The returntype.
1041: *
1042: * @since 1.0.0
1043: * @since 3.3.0 Revised.
1044: */
1045: function epl_property_icons( $returntype = 'i' ) {
1046: $returntype = empty( $returntype ) ? 'i' : $returntype;
1047: echo epl_get_property_icons( array(), $returntype ); //phpcs:ignore
1048: }
1049: add_action( 'epl_property_icons', 'epl_property_icons', 10, 1 );
1050:
1051: /**
1052: * Property bed/bath icons.
1053: *
1054: * @since 1.0
1055: *
1056: * @return string
1057: */
1058: function epl_get_property_bb_icons() {
1059: global $property;
1060: return $property->get_property_bed() . ' ' .
1061: $property->get_property_bath();
1062: }
1063:
1064: /**
1065: * Property land category
1066: *
1067: * @hooked property_land_category
1068: *
1069: * @since 1.0
1070: * @since 3.4.44 Fixed warning for preg_replace when value is empty.
1071: */
1072: function epl_property_land_category() {
1073: global $property;
1074: $land_category = $property->get_property_land_category();
1075:
1076: if ( empty( $land_category ) ) {
1077: return $land_category;
1078: }
1079:
1080: echo wp_kses_post( $land_category );
1081: }
1082: add_action( 'epl_property_land_category', 'epl_property_land_category' );
1083:
1084: /**
1085: * Property Commercial category
1086: *
1087: * @since 1.0 @hooked property_commercial_category
1088: */
1089: function epl_property_commercial_category() {
1090: global $property;
1091: if ( 'commercial' === $property->post_type ) {
1092: if ( 1 === (int) $property->get_property_meta( 'property_com_plus_outgoings' ) ) {
1093: echo '<div class="price-type">' . esc_html( apply_filters( 'epl_property_sub_title_plus_outgoings_label', __( 'Plus Outgoings', 'easy-property-listings' ) ) ) . '</div>';
1094: }
1095: echo wp_kses_post( $property->get_property_commercial_category() );
1096: }
1097: }
1098: add_action( 'epl_property_commercial_category', 'epl_property_commercial_category' );
1099:
1100: /**
1101: * Property Available Dates
1102: *
1103: * @since 1.0 @hooked property_available_dates
1104: */
1105: function epl_property_available_dates() {
1106: global $property;
1107: $date_avail = $property->get_property_meta( 'property_date_available' );
1108: if ( 'rental' === $property->post_type &&
1109: ! empty( $date_avail )
1110: && 'leased' !== $property->get_property_meta( 'property_status' ) ) {
1111: // Rental Specifics.
1112: echo '<div class="property-meta date-available">' . wp_kses_post( apply_filters( 'epl_property_sub_title_available_from_label', __( 'Available from', 'easy-property-listings' ) ) ) . ' ', wp_kses_post( $property->get_property_available() ), '</div>';
1113: }
1114: }
1115: add_action( 'epl_property_available_dates', 'epl_property_available_dates' );
1116:
1117: /**
1118: * Property Inspection Times
1119: *
1120: * @since 1.0 @hooked property_inspection_times
1121: * @since 3.4.44 Improvements for PHP 8.2
1122: */
1123: function epl_property_inspection_times() {
1124: global $property;
1125: $property_inspection_times = $property->get_property_inspection_times();
1126: $label_home_open = '';
1127:
1128: if ( ! empty( $property_inspection_times ) ) {
1129: $property_inspection_times = trim( $property_inspection_times );
1130: } else {
1131: return;
1132: }
1133:
1134: if ( ! empty( $property_inspection_times ) ) {
1135: $label_home_open = $property->get_epl_settings( 'label_home_open' );
1136:
1137: $label_home_open = apply_filters( 'epl_inspection_times_label', $label_home_open );
1138: ?>
1139: <div class="epl-inspection-times">
1140: <span class="epl-inspection-times-label">
1141: <?php echo wp_kses_post( $label_home_open ); ?>
1142: </span>
1143: <?php echo wp_kses_post( $property_inspection_times ); ?>
1144: </div>
1145: <?php
1146: }
1147: }
1148: add_action( 'epl_property_inspection_times', 'epl_property_inspection_times' );
1149:
1150: /**
1151: * Getting heading/title of the listing.
1152: *
1153: * @param mixed $listing listing instance.
1154: *
1155: * @since 2.3.1
1156: * @since 3.5.29 Fix PHP 8.1 deprecation when the listing has no heading.
1157: *
1158: * @return string listing heading or title
1159: */
1160: function epl_get_property_heading( $listing = null ) {
1161: if ( null === $listing ) {
1162: global $property;
1163: } elseif ( $listing instanceof EPL_Property_Meta ) {
1164: $property = $listing;
1165: } elseif ( $listing instanceof WP_Post ) {
1166: $property = new EPL_Property_Meta( $listing );
1167: } else {
1168: $property = get_post( $listing );
1169: $property = new EPL_Property_Meta( $property );
1170: }
1171:
1172: if ( $property ) {
1173: $property_heading = $property->get_property_meta( 'property_heading' );
1174: if ( null === $property_heading ) {
1175: $property_heading = '';
1176: }
1177: if ( strlen( trim( $property_heading ) ) ) {
1178: return $property_heading;
1179: }
1180: return get_the_title( $property->post->ID );
1181: }
1182: return '';
1183: }
1184:
1185: /**
1186: * Property Heading
1187: *
1188: * @since 1.0
1189: * @since 1.0 @hooked the_property_heading
1190: *
1191: * @param string $listing The listing.
1192: */
1193: function epl_property_heading( $listing = null ) {
1194: echo wp_kses_post( epl_get_property_heading( $listing ) );
1195: }
1196: add_action( 'epl_property_heading', 'epl_property_heading' );
1197:
1198: /**
1199: * Property Heading
1200: *
1201: * @since 1.0 @hooked property_secondary_heading
1202: * @since 3.4.41 Fix: Added land category.
1203: * @since 3.5.14 Corrected escaping function to esc_html.
1204: * @since 3.5.29 Fix PHP 8.1 deprecation when the meta value is empty.
1205: */
1206: function epl_property_secondary_heading() {
1207: global $property;
1208:
1209: if ( in_array( $property->post_type, array( 'rental', 'property' ), true ) ) {
1210: echo wp_kses_post( $property->get_property_category( 'span', 'epl-property-category' ) );
1211: }
1212:
1213: if ( 'rural' === $property->post_type ) {
1214: echo wp_kses_post( $property->get_property_rural_category( 'span', 'epl-rural-category' ) );
1215: }
1216:
1217: if ( 'land' === $property->post_type ) {
1218: echo wp_kses_post( $property->get_property_land_category( 'span', 'epl-land-category' ) );
1219: }
1220:
1221: if ( 'commercial' === $property->post_type || 'commercial_land' === $property->post_type ) {
1222: echo wp_kses_post( $property->get_property_commercial_category( 'span', 'epl-commercial-category' ) );
1223: }
1224:
1225: if ( 'sold' === $property->get_property_meta( 'property_status' ) ) {
1226: echo ' <span class="sold-status">' . esc_html( $property->label_sold ) . '</span>';
1227: }
1228:
1229: $suburb = $property->get_property_meta( 'property_address_suburb' );
1230: if ( null === $suburb ) {
1231: $suburb = '';
1232: }
1233:
1234: $state = $property->get_property_meta( 'property_address_state' );
1235: if ( null === $state ) {
1236: $state = '';
1237: }
1238:
1239: echo ' <span class="suburb"> - ' . wp_kses_post( $suburb ) . ' </span>';
1240: echo ' <span class="state">' . wp_kses_post( $state ) . '</span>';
1241: }
1242: add_action( 'epl_property_secondary_heading', 'epl_property_secondary_heading' );
1243:
1244: /**
1245: * Property Category
1246: *
1247: * @param string $tag The div tag.
1248: * @param string $classname The css class name.
1249: *
1250: * @since 1.0.0
1251: * @since 3.4.9 Removed passed 'value' option, added epl_property_category hook and passing of tag and class.
1252: */
1253: function epl_property_category( $tag = 'div', $classname = 'property-category' ) {
1254: global $property;
1255:
1256: if ( empty( $tag ) ) {
1257: $tag = 'div';
1258: }
1259:
1260: echo wp_kses_post( $property->get_property_category( $tag, $classname ) );
1261: }
1262: add_action( 'epl_property_category', 'epl_property_category', 10, 2 );
1263:
1264: /**
1265: * Video type
1266: *
1267: * @param string $url The url.
1268: * @return string
1269: *
1270: * @since 3.3.0
1271: * @since 3.6 Fix: PHP 8.1+ deprecation notice when the listing has no video URL (null).
1272: */
1273: function epl_get_video_host( $url ) {
1274:
1275: $host = 'unknown';
1276: $url = (string) $url;
1277:
1278: if ( strpos( $url, 'youtu' ) > 0 ) {
1279: $host = 'youtube';
1280: } elseif ( strpos( $url, 'vimeo' ) > 0 ) {
1281: $host = 'vimeo';
1282: }
1283:
1284: return $host;
1285: }
1286:
1287: /**
1288: * Property Video HTML
1289: *
1290: * @param string $property_video_url The property video url.
1291: * @param integer $width The width.
1292: *
1293: * @return string
1294: *
1295: * @since 1.0
1296: * @since 3.3
1297: * @since 3.4.38 Support for external/local hosted video formats like mp4, mov etc.
1298: * @since 3.4.42 Added support for youtube shorts & filter for video URL.
1299: */
1300: function epl_get_video_html( $property_video_url = '', $width = 600 ) {
1301:
1302: $property_video_url = apply_filters( 'epl_property_video_url', $property_video_url );
1303:
1304: // Remove related videos from YouTube.
1305: if ( 'youtube' === epl_get_video_host( $property_video_url ) ) {
1306:
1307: $property_video_url = epl_convert_youtube_embed_url( $property_video_url );
1308:
1309: if ( strpos( $property_video_url, '?' ) > 0 ) {
1310: $property_video_url .= '&rel=0';
1311: } else {
1312: $property_video_url .= '?rel=0';
1313: }
1314: }
1315: $width = epl_get_option( 'epl_video_width', $width );
1316: if ( ! empty( $property_video_url ) ) {
1317: $video_html = '<div class="epl-video-container videoContainer">';
1318:
1319: $video_embed_html = wp_oembed_get(
1320: $property_video_url,
1321: array( 'width' => apply_filters( 'epl_property_video_width', $width ) )
1322: );
1323:
1324: if ( $video_embed_html ) {
1325: $video_html .= $video_embed_html;
1326: } else {
1327: $video_html .= '<video class="epl-local-video" controls width="' . $width . '">
1328: <source src="' . $property_video_url . '">
1329: </video>';
1330: }
1331:
1332: $video_html .= '</div>';
1333:
1334: return $video_html;
1335: }
1336: }
1337:
1338: /**
1339: * Convert embed URLs to non embed URLs for WP Oembed compatibility.
1340: *
1341: * @param string $url The url.
1342: *
1343: * @return string converted URL
1344: * @since 3.4.27
1345: * @since 3.4.4 Added support for youtube shorts videos.
1346: */
1347: function epl_convert_youtube_embed_url( $url ) {
1348:
1349: if ( strpos( $url, 'embed' ) > 0 || strpos( $url, 'shorts' ) > 0 ) {
1350:
1351: $video_id = epl_get_youtube_id_from_url( $url );
1352:
1353: if ( ! empty( $video_id ) ) {
1354: $url = 'https://www.youtube.com/watch?v=' . $video_id;
1355: }
1356: }
1357:
1358: return apply_filters( 'epl_youtube_embed_url', $url );
1359: }
1360:
1361: /**
1362: * Video Output Function
1363: *
1364: * @hooked property_after_content
1365: *
1366: * @param integer $width The width.
1367: * @since 1.0
1368: * @since 3.3 Revised.
1369: * @since 3.4.44 Added check for empty videos.
1370: */
1371: function epl_property_video_callback( $width = 600 ) {
1372:
1373: global $property;
1374: $video_width = ! empty( $width ) ? $width : 600;
1375: $property_video_url = $property->get_property_meta( 'property_video_url' );
1376:
1377: if ( '' !== $property_video_url ) {
1378: echo epl_get_video_html( $property_video_url, $video_width ); //phpcs:ignore
1379: }
1380: }
1381: add_action( 'epl_property_video', 'epl_property_video_callback', 10, 1 );
1382:
1383: /**
1384: * Previous Video Hook, maintained for backward compatibility.
1385: *
1386: * @since 3.3
1387: * @hooked property_after_content
1388: */
1389: add_action( 'epl_property_content_after', 'epl_property_video_callback', 10, 1 );
1390:
1391: /**
1392: * Property Tab section details output
1393: *
1394: * @since 1.0.0
1395: * @since 3.4.14 Fix: Custom features' callback output wrongly placed.
1396: * @since 3.4.30 Fix: Property Features title set to pass basic html.
1397: * @since 3.5.0 New: epl_property_tab_section hook is replaced with epl_property_features, older hook is kept for backward compatibility.
1398: * @since 3.5.2 Tweak: Removed additional property category appearing in additional features list.
1399: * @since 3.5.14 Corrected escaping function to esc_html.
1400: *
1401: * @hooked property_tab_section
1402: */
1403: function epl_property_tab_section() {
1404: global $property;
1405: $post_type = $property->post_type;
1406: $the_property_feature_list = apply_filters( 'epl_the_property_feature_list_before', '' );
1407:
1408: $general_features_array = array(
1409: 'category',
1410: 'rural_category',
1411: 'commercial_category',
1412: 'bed',
1413: 'bath',
1414: 'rooms',
1415: 'year_built',
1416: 'parking',
1417: 'ac',
1418: 'pool',
1419: 'security',
1420: 'land_value',
1421: 'building_value',
1422: 'energy_rating',
1423: 'new_construction',
1424: );
1425:
1426: $general_features_array = apply_filters( 'epl_property_general_features_list', $general_features_array );
1427:
1428: foreach ( $general_features_array as $general_feature ) {
1429:
1430: switch ( $general_feature ) {
1431:
1432: case 'category':
1433: if ( 'property' === $post_type || 'rental' === $post_type ) {
1434: $the_property_feature_list .= $property->get_property_category( 'li' );
1435: }
1436:
1437: break;
1438:
1439: case 'rural_category':
1440: if ( 'rural' === $post_type ) {
1441: $the_property_feature_list .= $property->get_property_rural_category( 'li' );
1442: }
1443:
1444: break;
1445:
1446: case 'commercial_category':
1447: if ( 'commercial' === $post_type || 'commercial_land' === $post_type || 'business' === $post_type ) {
1448: $the_property_feature_list .= $property->get_property_commercial_category( 'li' );
1449: }
1450:
1451: break;
1452:
1453: case 'bed':
1454: $the_property_feature_list .= $property->get_property_bed( 'l' ) . ' ';
1455:
1456: break;
1457:
1458: case 'bath':
1459: $the_property_feature_list .= $property->get_property_bath( 'l' ) . ' ';
1460:
1461: break;
1462:
1463: case 'rooms':
1464: $the_property_feature_list .= $property->get_property_rooms( 'l' ) . ' ';
1465:
1466: break;
1467:
1468: case 'year_built':
1469: $the_property_feature_list .= $property->get_property_year_built( 'l' ) . ' ';
1470:
1471: break;
1472:
1473: case 'parking':
1474: $the_property_feature_list .= $property->get_property_parking( 'l' ) . ' ';
1475:
1476: break;
1477:
1478: case 'ac':
1479: $the_property_feature_list .= $property->get_property_air_conditioning( 'l' ) . ' ';
1480:
1481: break;
1482:
1483: case 'pool':
1484: $the_property_feature_list .= $property->get_property_pool( 'l' );
1485:
1486: break;
1487:
1488: case 'security':
1489: $the_property_feature_list .= $property->get_property_security_system( 'l' ) . ' ';
1490:
1491: break;
1492:
1493: case 'land_value':
1494: $the_property_feature_list .= $property->get_property_land_value( 'l' );
1495:
1496: break;
1497:
1498: case 'building_value':
1499: $the_property_feature_list .= $property->get_property_building_area_value( 'l' ) . ' ';
1500:
1501: break;
1502:
1503: case 'energy_rating':
1504: $the_property_feature_list .= $property->get_property_energy_rating( 'l' );
1505:
1506: break;
1507:
1508: case 'new_construction':
1509: $the_property_feature_list .= $property->get_property_new_construction( 'l' );
1510:
1511: break;
1512:
1513: default:
1514: ob_start();
1515: do_action( 'epl_property_general_feature_' . $general_feature );
1516: $the_property_feature_list .= ob_get_clean();
1517:
1518: break;
1519:
1520: }
1521: }
1522:
1523: $the_property_feature_list .= apply_filters( 'epl_the_property_feature_list_before_common_features', '' );
1524:
1525: $common_features = array(
1526: 'property_toilet',
1527: 'property_ensuite',
1528: 'property_pet_friendly',
1529: 'property_garage',
1530: 'property_carport',
1531: 'property_open_spaces',
1532: 'property_com_parking_comments',
1533: 'property_com_car_spaces',
1534: 'property_holiday_rental',
1535: 'property_furnished',
1536: );
1537: $common_features = apply_filters( 'epl_property_common_features_list', $common_features );
1538:
1539: foreach ( $common_features as $common_feature ) {
1540: $the_property_feature_list .= $property->get_additional_features_html( $common_feature );
1541: }
1542:
1543: $the_property_feature_list .= apply_filters( 'epl_the_property_feature_list_before_additional_features', '' );
1544:
1545: $additional_features = array(
1546: 'property_remote_garage',
1547: 'property_secure_parking',
1548: 'property_study',
1549: 'property_dishwasher',
1550: 'property_built_in_robes',
1551: 'property_gym',
1552: 'property_workshop',
1553: 'property_rumpus_room',
1554: 'property_floor_boards',
1555: 'property_broadband',
1556: 'property_pay_tv',
1557: 'property_vacuum_system',
1558: 'property_intercom',
1559: 'property_spa',
1560: 'property_tennis_court',
1561: 'property_balcony',
1562: 'property_deck',
1563: 'property_courtyard',
1564: 'property_outdoor_entertaining',
1565: 'property_shed',
1566: 'property_open_fire_place',
1567: 'property_ducted_heating',
1568: 'property_ducted_cooling',
1569: 'property_split_system_heating',
1570: 'property_hydronic_heating',
1571: 'property_split_system_aircon',
1572: 'property_gas_heating',
1573: 'property_reverse_cycle_aircon',
1574: 'property_evaporative_cooling',
1575: 'property_land_fully_fenced',
1576: );
1577: $additional_features = apply_filters( 'epl_property_additional_features_list', $additional_features );
1578:
1579: if ( 'property' === $property->post_type || 'rental' === $property->post_type || 'rural' === $property->post_type ) {
1580: foreach ( $additional_features as $additional_feature ) {
1581: $the_property_feature_list .= $property->get_additional_features_html( $additional_feature );
1582: }
1583: }
1584:
1585: $the_property_feature_list .= apply_filters( 'epl_the_property_feature_list_after', '' );
1586:
1587: if ( 'land' !== $property->post_type || 'business' !== $property->post_type ) {
1588: ?>
1589: <?php $property_features_title = apply_filters( 'epl_property_sub_title_property_features', __( 'Property Features', 'easy-property-listings' ) ); ?>
1590: <h5 class="epl-tab-title epl-tab-title-property-features tab-title"><?php echo wp_kses_post( $property_features_title ); ?></h5>
1591: <div class="epl-tab-content tab-content">
1592: <ul class="epl-property-features listing-info epl-tab-<?php echo esc_attr( $property->get_epl_settings( 'display_feature_columns' ) ); ?>-columns">
1593: <?php echo wp_kses_post( $the_property_feature_list . ' ' . $property->get_features_from_taxonomy() ); ?>
1594: </ul>
1595: </div>
1596: <?php } ?>
1597:
1598: <div class="epl-tab-content epl-tab-content-additional tab-content">
1599: <?php
1600: // Land Category.
1601: if ( 'land' === $property->post_type || 'commercial_land' === $property->post_type ) {
1602: echo '<div class="epl-land-category">' . wp_kses_post( $property->get_property_land_category( 'value' ) ) . '</div>';
1603: }
1604:
1605: // Commercial Options.
1606: if ( 'commercial' === $property->post_type ) {
1607: if ( 1 === (int) $property->get_property_meta( 'property_com_plus_outgoings' ) ) {
1608: echo '<div class="epl-commercial-outgoings price-type">' . wp_kses_post( apply_filters( 'epl_property_sub_title_plus_outgoings', __( 'Plus Outgoings', 'easy-property-listings' ) ) ) . '</div>';
1609: }
1610: }
1611: ?>
1612: </div>
1613: <?php
1614: }
1615: add_action( 'epl_property_tab_section', 'epl_property_tab_section' );
1616: add_action( 'epl_property_features', 'epl_property_tab_section' );
1617:
1618:
1619: /**
1620: * Property Tab section details output for commercial, business and commercial
1621: * land
1622: *
1623: * @hooked property_after_tab_section
1624: *
1625: * @since 1.0.0
1626: * @since 3.4.39 Using correctly spelt get_additional_commercial_features_html function.
1627: * @since 3.5.7 Filters added; epl_property_commercial_features_list and epl_property_rural_features_list filters.
1628: */
1629: function epl_property_tab_section_after() {
1630: global $property;
1631: $post_type = $property->post_type;
1632: if ( 'commercial' === $post_type || 'business' === $post_type || 'commercial_land' === $post_type ) {
1633:
1634: $the_property_commercial_feature_list = '';
1635: $features_lists = array(
1636: 'property_com_further_options',
1637: 'property_com_highlight_1',
1638: 'property_com_highlight_2',
1639: 'property_com_highlight_3',
1640: 'property_com_zone',
1641: );
1642:
1643: $features_lists = apply_filters( 'epl_property_commercial_features_list', $features_lists );
1644:
1645: // Check for values in the commercial features.
1646: $commercial_value = '';
1647:
1648: $result = array();
1649:
1650: foreach ( $features_lists as $feature ) {
1651:
1652: $commercial_value = $property->get_property_meta( $feature );
1653:
1654: if ( ! empty( $commercial_value ) ) {
1655: $result[] = $commercial_value;
1656: }
1657: }
1658:
1659: // Display results if $result array is not empty.
1660: if ( ! empty( $result ) ) {
1661:
1662: foreach ( $features_lists as $features_list ) {
1663: $the_property_commercial_feature_list .= $property->get_additional_commercial_features_html( $features_list );
1664: }
1665:
1666: ?>
1667: <div class="epl-tab-section epl-tab-section-commercial-features">
1668: <h5 class="epl-tab-title epl-tab-title-commercial-features tab-title"><?php echo wp_kses_post( apply_filters( 'epl_property_sub_title_commercial_features', __( 'Commercial Features', 'easy-property-listings' ) ) ); ?></h5>
1669: <div class="epl-tab-content tab-content">
1670: <div class="epl-commercial-features listing-info">
1671: <?php echo wp_kses_post( $the_property_commercial_feature_list ); ?>
1672: </div>
1673: </div>
1674: </div>
1675: <?php
1676: }
1677: }
1678:
1679: if ( 'rural' === $property->post_type ) {
1680: $the_property_rural_feature_list = '';
1681: $features_lists = array(
1682: 'property_rural_fencing',
1683: 'property_rural_annual_rainfall',
1684: 'property_rural_soil_types',
1685: 'property_rural_improvements',
1686: 'property_rural_council_rates',
1687: 'property_rural_irrigation',
1688: 'property_rural_carrying_capacity',
1689: );
1690:
1691: $features_lists = apply_filters( 'epl_property_rural_features_list', $features_lists );
1692:
1693: // Check for values in the rural features.
1694: $rural_value = '';
1695:
1696: $result = array();
1697:
1698: foreach ( $features_lists as $feature ) {
1699:
1700: $rural_value = $property->get_property_meta( $feature );
1701:
1702: if ( ! empty( $rural_value ) ) {
1703: $result[] = $rural_value;
1704: }
1705: }
1706:
1707: // Display results if $result array is not empty.
1708: if ( ! empty( $result ) ) {
1709:
1710: foreach ( $features_lists as $features_list ) {
1711: $the_property_rural_feature_list .= $property->get_additional_rural_features_html( $features_list );
1712: }
1713:
1714: ?>
1715: <div class="epl-tab-section epl-tab-section-rural-features">
1716: <h5 class="epl-tab-title epl-tab-title-rural-features tab-title"><?php echo wp_kses_post( apply_filters( 'epl_property_sub_title_rural_features', __( 'Rural Features', 'easy-property-listings' ) ) ); ?></h5>
1717: <div class="epl-tab-content tab-content">
1718: <div class="epl-rural-features listing-info">
1719: <?php echo wp_kses_post( $the_property_rural_feature_list ); ?>
1720: </div>
1721: </div>
1722: </div>
1723: <?php
1724: }
1725: }
1726: }
1727: add_action( 'epl_property_tab_section_after', 'epl_property_tab_section_after' );
1728:
1729: /**
1730: * Get price sticker
1731: *
1732: * @return string
1733: * @since 1.0
1734: */
1735: function epl_get_price_sticker() {
1736: global $property;
1737: return $property->get_price_sticker();
1738: }
1739:
1740: /**
1741: * Get Property Price
1742: *
1743: * @return string
1744: * @since 1.0
1745: */
1746: function epl_get_property_price() {
1747: global $property;
1748: return $property->get_price();
1749: }
1750:
1751: /**
1752: * Get listing Address for Widget
1753: *
1754: * @since 1.0
1755: *
1756: * @param string $d_suburb The d suburb.
1757: * @param string $d_street The d street.
1758: * @since 3.5.29 Fix PHP 8.1 deprecation when the meta value is empty.
1759: * @since 3.6 Uses the listing's show_suburb() and show_street_address() rules. Fix: a commercial or business listing showing its street address now shows its suburb even when Display Suburb is unticked, and commercial land listings follow Display Suburb, the same as epl_property_the_address().
1760: */
1761: function epl_widget_listing_address( $d_suburb = '', $d_street = '' ) {
1762: global $property;
1763:
1764: // Suburb.
1765: if ( 'on' === $d_suburb && $property->show_suburb() ) {
1766: $suburb = $property->get_property_meta( 'property_address_suburb' );
1767: if ( null === $suburb ) {
1768: $suburb = '';
1769: }
1770: ?>
1771: <div class="property-meta suburb-name"><?php echo esc_html( $suburb ); ?></div>
1772: <?php
1773: }
1774:
1775: // Street.
1776: if ( 'on' === $d_street && $property->show_street_address() ) {
1777: ?>
1778: <div class="property-meta street-name"><?php echo wp_kses_post( $property->get_formatted_property_address() ); ?></div>
1779: <?php
1780: }
1781: }
1782:
1783: /**
1784: * Get Sorting Options
1785: *
1786: * @param boolean $post_type The post type.
1787: *
1788: * @return mixed|void
1789: *
1790: * @since 2.0
1791: * @since 3.4.44 Option to sort by title.
1792: * @since 3.5.16 Tweak: Removed space after Status: in tools sorter. Added : colon to suburb for consistency.
1793: */
1794: function epl_sorting_options( $post_type = null ) {
1795: // phpcs:disable WordPress.Security.NonceVerification
1796: if ( is_null( $post_type ) ) {
1797: $post_type = isset( $_GET['post_type'] ) ? sanitize_text_field( wp_unslash( $_GET['post_type'] ) ) : 'property';
1798: }
1799:
1800: return apply_filters(
1801: 'epl_sorting_options',
1802: array(
1803: array(
1804: 'id' => 'high',
1805: 'label' => __( 'Price: High to Low', 'easy-property-listings' ),
1806: 'type' => 'meta',
1807: 'key' => 'property_price_global',
1808: 'order' => 'DESC',
1809: 'orderby' => 'meta_value_num',
1810: ),
1811: array(
1812: 'id' => 'low',
1813: 'label' => __( 'Price: Low to High', 'easy-property-listings' ),
1814: 'type' => 'meta',
1815: 'key' => 'property_price_global',
1816: 'order' => 'ASC',
1817: 'orderby' => 'meta_value_num',
1818:
1819: ),
1820: array(
1821: 'id' => 'new',
1822: 'label' => __( 'Date: Newest First', 'easy-property-listings' ),
1823: 'type' => 'post',
1824: 'key' => 'post_date',
1825: 'order' => 'DESC',
1826:
1827: ),
1828: array(
1829: 'id' => 'old',
1830: 'label' => __( 'Date: Oldest First', 'easy-property-listings' ),
1831: 'type' => 'post',
1832: 'key' => 'post_date',
1833: 'order' => 'ASC',
1834: ),
1835: array(
1836: 'id' => 'status_asc',
1837: 'label' => __( 'Status: Current First', 'easy-property-listings' ),
1838: 'type' => 'meta',
1839: 'key' => 'property_status',
1840: 'order' => 'ASC',
1841: 'orderby' => 'meta_value',
1842:
1843: ),
1844: array(
1845: 'id' => 'status_desc',
1846: 'label' => __( 'Status: Sold/Leased First', 'easy-property-listings' ),
1847: 'type' => 'meta',
1848: 'key' => 'property_status',
1849: 'order' => 'DESC',
1850: 'orderby' => 'meta_value',
1851:
1852: ),
1853: array(
1854: 'id' => 'location_asc',
1855: 'label' => epl_labels( 'label_suburb' ) . __( ': A-Z', 'easy-property-listings' ),
1856: 'type' => 'meta',
1857: 'key' => 'property_address_suburb',
1858: 'order' => 'ASC',
1859: 'orderby' => 'meta_value',
1860:
1861: ),
1862: array(
1863: 'id' => 'location_desc',
1864: 'label' => epl_labels( 'label_suburb' ) . __( ': Z-A', 'easy-property-listings' ),
1865: 'type' => 'meta',
1866: 'key' => 'property_address_suburb',
1867: 'order' => 'DESC',
1868: 'orderby' => 'meta_value',
1869:
1870: ),
1871: array(
1872: 'id' => 'title',
1873: 'label' => __( 'Title', 'easy-property-listings' ),
1874: 'type' => 'post',
1875: 'key' => 'post_title',
1876: 'order' => 'ASC',
1877:
1878: ),
1879: )
1880: );
1881: }
1882:
1883: /**
1884: * Switch Sorting Wrapper
1885: *
1886: * @param array $attributes Attributes.
1887: *
1888: * @since 3.3
1889: * @since 3.4.44 Get shortcode attributes as parameter.
1890: */
1891: function epl_tools_utility_wrapper( $attributes = array() ) {
1892:
1893: // Wrapper Start.
1894: do_action( 'epl_archive_utility_wrap_start', $attributes );
1895:
1896: do_action( 'epl_add_custom_menus', $attributes );
1897:
1898: // Wrapper End.
1899: do_action( 'epl_archive_utility_wrap_end', $attributes );
1900: }
1901: add_action( 'epl_property_loop_start', 'epl_tools_utility_wrapper', 10 );
1902:
1903: /**
1904: * Switch Sorting Wrapper
1905: *
1906: * @param array $attributes Attributes.
1907: * @param array $args Arguments.
1908: *
1909: * @since 3.4.44 Get shortcode attributes as parameter.
1910: * @since 3.5 Args missing second value.
1911: * @since 2.0
1912: * @since 3.3 Revised.
1913: */
1914: function epl_listing_toolbar_items( $attributes = array(), $args = array() ) {
1915: echo get_epl_listing_toolbar_items( $attributes, $args ); //phpcs:ignore;
1916: }
1917: add_action( 'epl_add_custom_menus', 'epl_listing_toolbar_items', 10, 2 );
1918:
1919: /**
1920: * Retrieves the switch and sorting options normally right aligned
1921: *
1922: * @param array $attributes Attributes.
1923: * @param array $args Arguments.
1924: *
1925: * @return string
1926: *
1927: * @since 3.3
1928: * @since 3.5 gets the shortcode attributes as param
1929: */
1930: function get_epl_listing_toolbar_items( $attributes = array(), $args = array() ) {
1931:
1932: $defaults = array(
1933: 'switch_views',
1934: 'sorting_tool',
1935: );
1936:
1937: $tools = apply_filters( 'epl_listing_toolbar_items', $defaults );
1938:
1939: ob_start();
1940:
1941: // Wrapper.
1942: if ( ! empty( $defaults ) ) {
1943: ?>
1944: <div class="epl-loop-tools epl-loop-tools-switch-sort epl-switching-sorting-wrap">
1945: <?php
1946:
1947: foreach ( $tools as $tool ) {
1948:
1949: if ( ! empty( $args ) && ! in_array( $tool, $args, true ) ) {
1950: continue;
1951: }
1952:
1953: switch ( $tool ) {
1954:
1955: case 'switch_views':
1956: do_action( 'epl_switch_views', $attributes );
1957: break;
1958:
1959: case 'sorting_tool':
1960: do_action( 'epl_sorting_tool', $attributes );
1961: break;
1962:
1963: default:
1964: // Action to hook additional tools.
1965: do_action( 'epl_listing_toolbar_' . $tool, $attributes );
1966: break;
1967: }
1968: }
1969: ?>
1970: </div>
1971: <?php
1972: }
1973: return ob_get_clean();
1974: }
1975:
1976: /**
1977: * Switch Views
1978: *
1979: * @since 2.0
1980: */
1981: function epl_switch_views() {
1982: ?>
1983: <div class="epl-loop-tool epl-tool-switch epl-switch-view">
1984: <ul>
1985: <li title="<?php echo esc_attr( apply_filters( 'epl_switch_views_sorting_title_list', __( 'List', 'easy-property-listings' ) ) ); ?>" class="epl-current-view view-list" data-view="list">
1986: </li>
1987: <li title="<?php echo esc_attr( apply_filters( 'epl_switch_views_sorting_title_grid', __( 'Grid', 'easy-property-listings' ) ) ); ?>" class="view-grid" data-view="grid">
1988: </li>
1989: </ul>
1990: </div>
1991: <?php
1992: }
1993: add_action( 'epl_switch_views', 'epl_switch_views' );
1994:
1995: /**
1996: * Displays the Switch Sorting select options
1997: *
1998: * @param array $attributes Attributes.
1999: *
2000: * @since 2.0
2001: * @since 3.3 Revised.
2002: * @since 3.4.44 Unique ID for sort dropdown per instance.
2003: * @since 3.4.44 Get shortcode attributes as parameter.
2004: * @since 3.5 Added accessibility labels to select elements.
2005: * @since 3.5.7 Instance ID default to 1 to enable sorting. The $attributes option is required.
2006: * @since 3.5.14 Corrected escaping function to esc_html.
2007: */
2008: function epl_sorting_tool( $attributes = array() ) {
2009:
2010: $instance_id = ! empty( $attributes['instance_id'] ) ? sanitize_text_field( $attributes['instance_id'] ) : '1';
2011: $sortby = '';
2012: $set_instance_id = '';
2013: if ( ! empty( $_GET['sortby'] ) ) {
2014: $sortby = sanitize_text_field( wp_unslash( $_GET['sortby'] ) );
2015: }
2016: if ( ! empty( $_GET['instance_id'] ) ) {
2017: $set_instance_id = sanitize_text_field( wp_unslash( $_GET['instance_id'] ) );
2018: }
2019: $sorters = epl_sorting_options();
2020: $id = ! empty( $instance_id ) ? $instance_id : '1';
2021: ?>
2022:
2023: <div class="epl-loop-tool epl-tool-sorting epl-properties-sorting epl-clearfix">
2024: <select aria-label="<?php esc_attr_e( 'Sort Listings', 'easy-property-listings' ); ?>" class="epl-sort-listings" id="epl-sort-listings-<?php echo esc_attr( $instance_id ); ?>" data-instance-id="<?php echo esc_attr( $instance_id ); ?>">
2025: <option <?php selected( $sortby, '' ); ?> value="">
2026: <?php echo esc_html( apply_filters( 'epl_switch_views_sorting_title_sort', __( 'Sort', 'easy-property-listings' ) ) ); ?>
2027: </option>
2028: <?php
2029: foreach ( $sorters as $sorter ) {
2030:
2031: if ( ! empty( $instance_id ) ) {
2032: $sortbyinstance = $set_instance_id . '_' . $sortby;
2033: $sorter_id = $instance_id . '_' . $sorter['id'];
2034: } else {
2035: $sortbyinstance = $sortby;
2036: $sorter_id = $sorter['id'];
2037: }
2038: ?>
2039: <option <?php selected( $sortbyinstance, $sorter_id ); ?> value="<?php echo esc_attr( $sorter['id'] ); ?>">
2040: <?php echo esc_html( $sorter['label'] ); ?>
2041: </option>
2042: <?php
2043: }
2044: ?>
2045: </select>
2046: </div>
2047: <?php
2048: }
2049: add_action( 'epl_sorting_tool', 'epl_sorting_tool' );
2050:
2051: /**
2052: * Displays the Sorting tabs
2053: *
2054: * @since 3.3
2055: * @since 3.5.14 Corrected escaping function to esc_html.
2056: */
2057: function epl_sorting_tabs() {
2058: $sortby = '';
2059: if ( ! empty( $_GET['sortby'] ) ) {
2060: $sortby = sanitize_text_field( wp_unslash( $_GET['sortby'] ) );
2061: }
2062: $sorters = epl_sorting_options();
2063:
2064: global $wp;
2065: $get_data = $_GET;
2066: $get_data = array_map( 'sanitize_text_field', $get_data );
2067: $current_url = home_url( add_query_arg( array( $get_data ), $wp->request ) );
2068: ?>
2069:
2070: <div class="epl-loop-tool epl-tool-sorting-tabs epl-properties-sorting epl-clearfix">
2071: <ul id="epl-sort-tabs-listings">
2072: <?php
2073: foreach ( $sorters as $sorter ) {
2074: $href = epl_add_or_update_params( $current_url, 'sortby', $sorter['id'] );
2075: $class = $sortby === $sorter['id'] ? 'epl-sortby-selected' : '';
2076: ?>
2077: <li class="epl-sortby-list <?php echo esc_attr( $class ); ?>">
2078: <a href="<?php echo esc_url( $href ); ?>">
2079: <?php echo esc_html( $sorter['label'] ); ?>
2080: </a>
2081: </li>
2082: <?php
2083: }
2084: ?>
2085: </ul>
2086: </div>
2087: <?php
2088: }
2089:
2090: /**
2091: * Update parameters
2092: *
2093: * @param string $url The url.
2094: * @param string $key The key.
2095: * @param string $value The value.
2096: *
2097: * @return string
2098: * @since 3.3
2099: * @since 3.5 Fix: Warning when url empty.
2100: */
2101: function epl_add_or_update_params( $url, $key, $value ) {
2102:
2103: if ( empty( $url ) ) {
2104: return $url;
2105: }
2106:
2107: $a = wp_parse_url( $url );
2108: $query = isset( $a['query'] ) ? $a['query'] : '';
2109: parse_str( $query, $params );
2110: $params[ $key ] = $value;
2111: $query = http_build_query( $params );
2112: $result = '';
2113: if ( $a['scheme'] ) {
2114: $result .= $a['scheme'] . ':';
2115: }
2116: if ( $a['host'] ) {
2117: $result .= '//' . $a['host'];
2118: }
2119: if ( ! empty( $a['port'] ) ) {
2120: $result .= ':' . $a['port'];
2121: }
2122: if ( $a['path'] ) {
2123: $result .= $a['path'];
2124: }
2125: if ( $query ) {
2126: $result .= '?' . $query;
2127: }
2128: return $result;
2129: }
2130:
2131: /**
2132: * Query arguments for a sorter from epl_sorting_options()
2133: *
2134: * Adds tiebreakers so listings with the same value (the same status, suburb, price or post
2135: * date) come back in a fixed order. Without them MySQL returns ties in any order, so a
2136: * listing can show on two pages, or on none, when paging through sorted results. Meta and
2137: * title sorts break ties by newest first, then ID. Date sorts break ties by ID in the same
2138: * direction. A random sort, or a sorter whose orderby already lists several keys, is used
2139: * as is.
2140: *
2141: * @param array $sorter A sorter: type (meta or post), key, order and, for meta, orderby.
2142: *
2143: * @return array WP_Query arguments: orderby, order and, for meta sorters, meta_key.
2144: *
2145: * @since 3.6
2146: */
2147: function epl_get_sorter_query_args( $sorter ) {
2148: $order = isset( $sorter['order'] ) && 'ASC' === strtoupper( $sorter['order'] ) ? 'ASC' : 'DESC';
2149: $is_meta = isset( $sorter['type'] ) && 'meta' === $sorter['type'];
2150: $key = isset( $sorter['key'] ) ? $sorter['key'] : '';
2151: $primary = $is_meta ? ( isset( $sorter['orderby'] ) ? $sorter['orderby'] : 'meta_value' ) : $key;
2152:
2153: $args = array( 'order' => $order );
2154:
2155: if ( $is_meta ) {
2156: $args['meta_key'] = $key; //phpcs:ignore
2157: }
2158:
2159: if ( ! is_string( $primary ) || '' === $primary || false !== strpos( trim( $primary ), ' ' ) || in_array( $primary, array( 'rand', 'none' ), true ) || 0 === strpos( $primary, 'RAND(' ) ) {
2160: $args['orderby'] = $primary;
2161: return $args;
2162: }
2163:
2164: $orderby = array( $primary => $order );
2165:
2166: if ( in_array( $primary, array( 'date', 'post_date' ), true ) ) {
2167: $orderby['ID'] = $order;
2168: } elseif ( 'ID' !== $primary ) {
2169: $orderby['date'] = 'DESC';
2170: $orderby['ID'] = 'DESC';
2171: }
2172:
2173: /**
2174: * Filters the orderby array, primary sort first, then the tiebreakers.
2175: *
2176: * @since 3.6
2177: *
2178: * @param array $orderby Orderby => order pairs.
2179: * @param array $sorter The sorter.
2180: */
2181: $args['orderby'] = apply_filters( 'epl_sorter_orderby', $orderby, $sorter );
2182:
2183: return $args;
2184: }
2185:
2186: /**
2187: * Archive Sorting
2188: *
2189: * @param WP_Query $query The query.
2190: *
2191: * @since 2.0
2192: * @since 3.6 Sorting has tiebreakers (epl_get_sorter_query_args()), so listings with the same value don't repeat or go missing across pages.
2193: */
2194: function epl_archive_sorting( $query ) {
2195: $post_types_sold = array( 'property', 'land', 'commercial', 'business', 'commercial_land', 'location_profile', 'rural' );
2196: $post_types_rental = array( 'rental' );
2197:
2198: if ( ! $query->is_main_query() ) {
2199: return;
2200: }
2201:
2202: if ( is_post_type_archive( $post_types_sold ) || is_post_type_archive( $post_types_rental ) || is_tax( 'location' ) || is_tax( 'tax_feature' ) || is_tax( 'tax_business_listing' ) || epl_is_search() ) {
2203:
2204: if ( ! empty( $_GET['sortby'] ) ) {
2205:
2206: $orderby = sanitize_text_field( wp_unslash( $_GET['sortby'] ) );
2207: $sorters = epl_sorting_options( $query->get( 'post_type' ) );
2208:
2209: foreach ( $sorters as $sorter ) {
2210:
2211: if ( $orderby === $sorter['id'] ) {
2212:
2213: foreach ( epl_get_sorter_query_args( $sorter ) as $arg => $value ) {
2214: $query->set( $arg, $value );
2215: }
2216: break;
2217: }
2218: }
2219: }
2220: }
2221: }
2222: add_action( 'pre_get_posts', 'epl_archive_sorting' );
2223:
2224: /**
2225: * Author Tabs
2226: *
2227: * @param array|null $epl_author EPL author object.
2228: *
2229: * @return array
2230: *
2231: * @since 1.0.0
2232: * @since 3.5.2 Passes param $epl_author so it can be passed to tabs filter.
2233: */
2234: function epl_author_tabs( $epl_author = null ) {
2235:
2236: if ( is_null( $epl_author ) ) {
2237: global $epl_author;
2238: }
2239: $author_tabs = array(
2240: 'author_id' => __( 'About', 'easy-property-listings' ),
2241: 'description' => __( 'Bio', 'easy-property-listings' ),
2242: 'video' => __( 'Video', 'easy-property-listings' ),
2243: 'contact_form' => __( 'Contact', 'easy-property-listings' ),
2244: );
2245: $author_tabs = apply_filters( 'epl_author_tabs', $author_tabs, $epl_author );
2246: return $author_tabs;
2247: }
2248:
2249: /**
2250: * Author Class
2251: *
2252: * @since 2.0
2253: *
2254: * @param string $classes The classes.
2255: */
2256: function epl_author_class( $classes ) {
2257: $classes = explode( ' ', $classes . ' epl-author-box author-box' );
2258: $classes = array_filter( array_unique( $classes ) );
2259: $classes = apply_filters( 'epl_author_class', $classes );
2260: if ( ! empty( $classes ) ) {
2261: $classes = implode( ' ', $classes );
2262: echo esc_attr( $classes );
2263: }
2264: }
2265:
2266: /**
2267: * Author Tab ID
2268: *
2269: * @since 2.0
2270: *
2271: * @param array $epl_author The epl author.
2272: *
2273: * @return false|string
2274: */
2275: function epl_author_tab_author_id( $epl_author = array() ) {
2276:
2277: if ( empty( $epl_author ) ) {
2278: global $epl_author;
2279: }
2280:
2281: $permalink = apply_filters( 'epl_author_profile_link', get_author_posts_url( $epl_author->author_id ), $epl_author );
2282: $author_title = apply_filters( 'epl_author_profile_title', get_the_author_meta( 'display_name', $epl_author->author_id ), $epl_author );
2283:
2284: $arg_list = get_defined_vars();
2285:
2286: ob_start();
2287:
2288: epl_get_template_part( 'content-author-box-tab-details.php', $arg_list );
2289:
2290: return ob_get_clean();
2291: }
2292:
2293: /**
2294: * Author Tab Image
2295: *
2296: * @since 2.0
2297: *
2298: * @param array $epl_author The epl author.
2299: */
2300: function epl_author_tab_image( $epl_author = array() ) {
2301:
2302: if ( empty( $epl_author ) ) {
2303: global $epl_author;
2304: }
2305:
2306: if ( function_exists( 'get_avatar' ) ) {
2307: echo wp_kses_post( apply_filters( 'epl_author_tab_image', get_avatar( $epl_author->email, '150' ), $epl_author ) );
2308: }
2309: }
2310: add_action( 'epl_author_thumbnail', 'epl_author_tab_image', 10, 2 );
2311:
2312: /**
2313: * Author Tab Description
2314: *
2315: * @since 1.0
2316: *
2317: * @param array $epl_author The epl author.
2318: */
2319: function epl_author_tab_description( $epl_author = array() ) {
2320: if ( empty( $epl_author ) ) {
2321: global $epl_author;
2322: }
2323: echo wp_kses_post( $epl_author->get_description_html() );
2324: }
2325:
2326: /**
2327: * Author Tab Video
2328: *
2329: * @since 1.0
2330: *
2331: * @param array $epl_author The epl author.
2332: */
2333: function epl_author_tab_video( $epl_author = array() ) {
2334: if ( empty( $epl_author ) ) {
2335: global $epl_author;
2336: }
2337: $video_html = $epl_author->get_video_html();
2338: if ( ! empty( $video_html ) ) {
2339: echo '<div class="epl-author-video author-video epl-video-container">' . $video_html . '</div>'; //phpcs:ignore
2340: }
2341: }
2342:
2343: /**
2344: * Author Tab Contact Form
2345: *
2346: * @since 1.0
2347: *
2348: * @param array $epl_author The epl author.
2349: */
2350: function epl_author_tab_contact_form( $epl_author = array() ) {
2351: if ( empty( $epl_author ) ) {
2352: global $epl_author;
2353: }
2354: echo $epl_author->get_author_contact_form(); //phpcs:ignore
2355: }
2356:
2357: /**
2358: * Archive Utility Wrapper Before
2359: *
2360: * @since 1.0
2361: */
2362: function epl_archive_utility_wrap_before() {
2363: echo '<div class="epl-loop-tools-wrap epl-archive-utility-wrapper epl-clearfix">';
2364: }
2365: add_action( 'epl_archive_utility_wrap_start', 'epl_archive_utility_wrap_before' );
2366:
2367: /**
2368: * Archive Utility Wrapper After
2369: *
2370: * @since 1.0
2371: */
2372: function epl_archive_utility_wrap_after() {
2373: echo '</div>';
2374: }
2375: add_action( 'epl_archive_utility_wrap_end', 'epl_archive_utility_wrap_after' );
2376:
2377: /**
2378: * Listing Image Gallery
2379: *
2380: * @since 1.0
2381: * @since 3.3 Revised.
2382: * @since 3.6 New filter epl_property_gallery_html: an add-on can supply the whole gallery HTML (for example CDN-hosted images not in the media library).
2383: */
2384: function epl_property_gallery() {
2385:
2386: $d_gallery = (int) epl_get_option( 'display_single_gallery' );
2387:
2388: $d_gallery_n = epl_get_option( 'display_gallery_n' );
2389:
2390: if ( 1 !== $d_gallery ) {
2391: return;
2392: }
2393:
2394: /**
2395: * Allow an extension to fully supply the gallery HTML (e.g. CDN-hosted images
2396: * that are not in the WP media library). Return a string to short-circuit the
2397: * default attachment-based gallery; return null to leave default behaviour.
2398: *
2399: * @since 3.6
2400: *
2401: * @param string|null $custom Custom gallery HTML, or null for default.
2402: * @param int $post_id Current listing ID.
2403: */
2404: $custom = apply_filters( 'epl_property_gallery_html', null, get_the_ID() );
2405: if ( null !== $custom ) {
2406: echo $custom; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2407: return;
2408: }
2409:
2410: $attachments = get_children(
2411: array(
2412: 'post_parent' => get_the_ID(),
2413: 'post_type' => 'attachment',
2414: 'post_mime_type' => 'image',
2415: )
2416: );
2417:
2418: if ( $attachments ) {
2419: ?>
2420:
2421: <div class="epl-gallery property-gallery">
2422: <!-- Gallery -->
2423: <div class="epl-gallery-entry entry-gallery epl-clearfix">
2424: <?php
2425: $gallery_shortcode = '[gallery columns="' . $d_gallery_n . '" link="file"]';
2426: $gallery = apply_filters( 'epl_property_gallery_shortcode', $gallery_shortcode, $d_gallery_n );
2427: echo do_shortcode( $gallery ); // phpcs:ignore
2428: ?>
2429: </div>
2430: </div>
2431: <?php
2432: }
2433: }
2434: add_action( 'epl_property_gallery', 'epl_property_gallery' );
2435:
2436: /**
2437: * Get the template path.
2438: *
2439: * @return string
2440: * @since 1.0
2441: */
2442: function epl_template_path() {
2443: return apply_filters( 'epl_template_path', 'easypropertylistings/' );
2444: }
2445:
2446: /**
2447: * Outputs a wrapper div before the first button
2448: *
2449: * @since 1.3
2450: */
2451: function epl_buttons_wrapper_before() {
2452: echo '<div class="epl-button-wrapper epl-clearfix">';
2453: }
2454:
2455: /**
2456: * Outputs a wrapper div after the last button
2457: *
2458: * @since 1.3
2459: */
2460: function epl_buttons_wrapper_after() {
2461: echo '</div>';
2462: }
2463: add_action( 'epl_buttons_single_property', 'epl_buttons_wrapper_before', 1 );
2464: add_action( 'epl_buttons_single_property', 'epl_buttons_wrapper_after', 99 );
2465:
2466: /**
2467: * Used to mark home inspection on Apple devices
2468: *
2469: * @param string $start The start.
2470: * @param string $end The end.
2471: * @param string $name The name.
2472: * @param string $description The description.
2473: * @param string $location The location.
2474: * @param null $post_id The post ID.
2475: *
2476: * @since 2.0.0
2477: * @since 3.4.9 Corrected issue where output was trimmed, added better unique ID and URL to output.
2478: * @since 3.5.7 Updated to allow passing of extra details to ical.
2479: * @since 3.5.21 Sanitized generated iCal filename and added fallback filename handling.
2480: */
2481: function epl_create_ical_file( $start = '', $end = '', $name = '', $description = '', $location = '', $post_id = null ) {
2482:
2483: if ( is_null( $post_id ) ) {
2484: $post_id = get_the_ID();
2485: }
2486:
2487: $description = str_replace( "\n", "\\n", str_replace( ';', '\;', str_replace( ',', '\,', $description ) ) );
2488: $uid = $post_id . time();
2489: $url = get_permalink( $post_id );
2490: $prodid = '-//' . get_bloginfo( 'name' ) . '/EPL//NONSGML v1.0//EN';
2491: $file_name = sanitize_file_name( $name );
2492: if ( '' === $file_name ) {
2493: $file_name = 'event';
2494: }
2495: $args = get_defined_vars();
2496: $args = apply_filters( 'epl_ical_args', $args );
2497: $data = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:" . $args['prodid'] . "\nMETHOD:PUBLISH\nBEGIN:VEVENT\nDTSTART:" . gmdate( 'Ymd\THis', strtotime( $args['start'] ) ) . "\nDTEND:" . gmdate( 'Ymd\THis', strtotime( $args['end'] ) ) . "\nLOCATION:" . $args['location'] . "\nURL:" . $args['url'] . "\nTRANSP:OPAQUE\nSEQUENCE:0\nUID:" . $args['uid'] . "\nDTSTAMP:" . gmdate( 'Ymd\THis\Z' ) . "\nSUMMARY:" . $args['name'] . "\nDESCRIPTION:" . $args['description'] . "\nPRIORITY:1\nCLASS:PUBLIC\nBEGIN:VALARM\nTRIGGER:-PT10080M\nACTION:DISPLAY\nDESCRIPTION:Reminder\nEND:VALARM\nEND:VEVENT\nEND:VCALENDAR\n";
2498:
2499: header( 'Content-type:text/calendar' );
2500: header( 'Content-Disposition: attachment; filename="' . $file_name . '.ics"' );
2501: Header( 'Content-Length: ' . strlen( $data ) );
2502: Header( 'Connection: close' );
2503: echo $data; //phpcs:ignore
2504: die;
2505: }
2506:
2507: /**
2508: * Output iCal clickable dates. Use the epl_ical_args filter to alter the labels.
2509: *
2510: * @since 2.0
2511: * @since 3.5.7 Different subject for auction.
2512: * @since 3.5.16 Triple equals for auction value.
2513: * @since 3.5.20 ical access issue.
2514: * @since 3.5.21 Added signed token validation for iCal download requests and introduced filterable iCal event description. iCal description now uses the excerpt instead of full content.
2515: */
2516: function epl_process_event_cal_request() {
2517: global $epl_settings;
2518: if ( ! isset( $_GET['propid'], $_GET['epl_cal_dl'], $_GET['cal'], $_GET['dt'] ) || 1 !== (int) $_GET['epl_cal_dl'] ) {
2519: return;
2520: }
2521:
2522: $post_id = absint( wp_unslash( $_GET['propid'] ) );
2523: if ( $post_id <= 0 || 'ical' !== sanitize_text_field( wp_unslash( $_GET['cal'] ) ) ) {
2524: return;
2525: }
2526:
2527: $item = base64_decode( sanitize_text_field( wp_unslash( $_GET['dt'] ) ), true ); //phpcs:ignore
2528: if ( false === $item ) {
2529: return;
2530: }
2531:
2532: $item = trim( html_entity_decode( $item, ENT_QUOTES, 'UTF-8' ) );
2533: if ( '' === $item || ! isset( $item[0] ) || ! is_numeric( $item[0] ) ) {
2534: return;
2535: }
2536:
2537: $token = isset( $_GET['k'] ) ? sanitize_text_field( wp_unslash( $_GET['k'] ) ) : '';
2538: $valid = ! empty( $token ) && hash_equals( epl_get_ical_download_token( $post_id, $item ), $token );
2539:
2540: $allow_legacy_access = apply_filters( 'epl_allow_legacy_ical_access', false, $post_id, $item );
2541: if ( ! $valid && ! $allow_legacy_access && ! current_user_can( 'manage_options' ) ) {
2542: return;
2543: }
2544:
2545: $post = get_post( $post_id );
2546: if ( is_null( $post ) || 'publish' !== $post->post_status || ! in_array( $post->post_type, epl_get_core_post_types(), true ) || post_password_required( $post_id ) ) {
2547: return;
2548: }
2549:
2550: $inspection_time = get_post_meta( $post_id, 'property_inspection_times', true );
2551: if ( ! is_string( $inspection_time ) || '' === trim( $inspection_time ) ) {
2552: return;
2553: }
2554:
2555: $is_valid_inspection = false;
2556: $list = array_filter( explode( "\n", trim( $inspection_time ) ) );
2557: foreach ( $list as $inspection_item ) {
2558: $inspection_item = trim( $inspection_item );
2559: if ( '' === $inspection_item || ! isset( $inspection_item[0] ) || ! is_numeric( $inspection_item[0] ) ) {
2560: continue;
2561: }
2562:
2563: $timearr = explode( ' ', $inspection_item );
2564: $endtime = current( $timearr ) . ' ' . end( $timearr );
2565: $expired = strtotime( $endtime ) < epl_get_local_timestamp();
2566: $expired = apply_filters( 'epl_maybe_delete_inspection', $expired, $endtime, $inspection_item );
2567: if ( $expired ) {
2568: continue;
2569: }
2570:
2571: if ( $inspection_item === $item ) {
2572: $is_valid_inspection = true;
2573: break;
2574: }
2575: }
2576:
2577: if ( ! $is_valid_inspection ) {
2578: return;
2579: }
2580:
2581: $timearr = explode( ' ', $item );
2582: $starttime = current( $timearr );
2583: if ( isset( $timearr[1] ) ) {
2584: $starttime .= ' ' . $timearr[1];
2585: }
2586: $endtime = current( $timearr ) . ' ' . end( $timearr );
2587:
2588: $subject = $epl_settings['label_home_open'] . ' - ' . get_post_meta( $post_id, 'property_heading', true );
2589: if ( isset( $_GET['event_type'] ) && 'auction' === sanitize_text_field( wp_unslash( $_GET['event_type'] ) ) ) {
2590: $subject = __( 'Auction', 'easy-property-listings' ) . ' - ' . get_post_meta( $post_id, 'property_heading', true );
2591: }
2592:
2593: $address = '';
2594: $prop_sub_num = get_post_meta( $post_id, 'property_address_sub_number', true );
2595: if ( ! empty( $prop_sub_num ) ) {
2596: $address .= get_post_meta( $post_id, 'property_address_sub_number', true ) . '/';
2597: }
2598: $address .= get_post_meta( $post_id, 'property_address_street_number', true ) . ' ';
2599: $address .= get_post_meta( $post_id, 'property_address_street', true ) . ' ';
2600: $address .= get_post_meta( $post_id, 'property_address_suburb', true ) . ', ';
2601: $address .= get_post_meta( $post_id, 'property_address_state', true ) . ' ';
2602: $address .= get_post_meta( $post_id, 'property_address_postal_code', true );
2603:
2604: $description = wp_strip_all_tags( get_the_excerpt( $post ) );
2605: $description = apply_filters( 'epl_ical_description', $description, $post_id, $post, $item );
2606:
2607: epl_create_ical_file( $starttime, $endtime, $subject, $description, $address, $post_id );
2608: }
2609: add_action( 'init', 'epl_process_event_cal_request' );
2610:
2611: /**
2612: * Add coordinates to meta for faster loading on second view
2613: *
2614: * @since 2.1
2615: * @since 3.5.3 Removed nopriv access & added nonce.
2616: * @since 3.5.4 Fix: Check user permissions on coordinate generation.
2617: */
2618: function epl_update_listing_coordinates() {
2619:
2620: check_ajax_referer( 'epl_ajax_nonce', '_epl_nonce' );
2621:
2622: if ( ! current_user_can( 'manage_options' ) ) {
2623: wp_die( 'fail' );
2624: }
2625:
2626: if ( ( ! isset( $_POST['listid'] ) || 0 === intval( $_POST['listid'] ) ) || empty( $_POST['coordinates'] ) ) {
2627: return;
2628: }
2629: $coordinates = rtrim( ltrim( sanitize_text_field( wp_unslash( $_POST['coordinates'] ) ), '(' ), ')' ); //phpcs:ignore
2630: if ( update_post_meta( intval( wp_unslash( $_POST['listid'] ) ), 'property_address_coordinates', $coordinates ) ) { //phpcs:ignore
2631: wp_die( 'success' );
2632: } else {
2633: wp_die( 'fail' );
2634: }
2635: }
2636: add_action( 'wp_ajax_epl_update_listing_coordinates', 'epl_update_listing_coordinates' );
2637:
2638: /**
2639: * Adapted from wp core to add additional filters
2640: *
2641: * @param string $id The identifier.
2642: * @param string $taxonomy The taxonomy.
2643: * @param string $before The before.
2644: * @param string $sep The separator.
2645: * @param string $after The after.
2646: *
2647: * @return bool|false|string|WP_Error|WP_Term[]
2648: *
2649: * @since 2.1
2650: * @since 3.3 Revised.
2651: * @since 3.5.1 Dynamic class name for item based on taxonomy.
2652: */
2653: function epl_get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) {
2654: $terms = get_the_terms( $id, $taxonomy );
2655:
2656: if ( is_wp_error( $terms ) ) {
2657: return $terms;
2658: }
2659:
2660: if ( empty( $terms ) ) {
2661: return false;
2662: }
2663:
2664: foreach ( $terms as $term ) {
2665:
2666: $link = get_term_link( $term, $taxonomy );
2667: if ( is_wp_error( $link ) ) {
2668: return $link;
2669: }
2670:
2671: if ( true === apply_filters( 'epl_features_taxonomy_link_filter', true ) ) {
2672: $term_links[] = '<li class="epl-tax-' . $taxonomy . ' ' . $term->slug . ' ">' .
2673: '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>'
2674: . '</li>' . $sep;
2675: } else {
2676: $term_links[] = '<li class="epl-tax-' . $taxonomy . ' ' . $term->slug . ' ">' . $term->name . '</li>' . $sep;
2677: }
2678: }
2679:
2680: $term_links = apply_filters( "term_links-$taxonomy", $term_links ); //phpcs:ignore
2681:
2682: $html = $before;
2683: foreach ( $term_links as $term_link ) {
2684: $html .= $term_link;
2685: }
2686: $html .= $after;
2687:
2688: return $html;
2689: }
2690:
2691: /**
2692: * Get Property Meta
2693: *
2694: * @param string $key Meta key.
2695: *
2696: * @return string $key The property meta.
2697: * @since 2.1
2698: */
2699: function get_property_meta( $key ) {
2700: global $property;
2701: return $property->get_property_meta( $key );
2702: }
2703:
2704: /**
2705: * The Property Meta
2706: *
2707: * @since 2.1
2708: *
2709: * @param string $key The key.
2710: * @since 3.5.29 Fix PHP 8.1 deprecation when the meta value is empty.
2711: */
2712: function the_property_meta( $key ) {
2713: global $property;
2714:
2715: $value = $property->get_property_meta( $key );
2716: if ( null === $value ) {
2717: $value = '';
2718: }
2719:
2720: echo wp_kses_post( $value );
2721: }
2722:
2723: /**
2724: * Template Class
2725: *
2726: * @since 2.1
2727: *
2728: * @param boolean $classname The class.
2729: * @param string $context The context.
2730: *
2731: * @return mixed|void
2732: */
2733: function epl_template_class( $classname = false, $context = 'single' ) {
2734:
2735: if ( $classname ) {
2736: $classname = 'epl-template-' . $classname;
2737: } else {
2738: $classname = 'epl-template-blog';
2739: }
2740:
2741: return apply_filters( 'epl_template_class', $classname, $context );
2742: }
2743:
2744: /**
2745: * Pagination
2746: *
2747: * @since 2.1
2748: *
2749: * @param array $query The query.
2750: */
2751: function epl_pagination( $query = array() ) {
2752: global $epl_settings;
2753: $fancy_on = 1 === (int) epl_get_option( 'use_fancy_navigation', 0 ) ? 1 : 0;
2754: if ( $fancy_on ) {
2755: epl_fancy_pagination( $query );
2756: } else {
2757: epl_wp_default_pagination( $query );
2758: }
2759: }
2760: add_action( 'epl_pagination', 'epl_pagination' );
2761:
2762: /**
2763: * Returns active theme name as a lowercase name
2764: *
2765: * @since 3.0
2766: *
2767: * @return string
2768: */
2769: function epl_get_active_theme() {
2770: if ( function_exists( 'wp_get_theme' ) ) { // wp version >= 3.4.
2771: $active_theme = wp_get_theme();
2772: $active_theme = $active_theme->get( 'Name' );
2773:
2774: } else {
2775: // older versions.
2776: $active_theme = wp_get_theme(); //phpcs:ignore
2777: }
2778: $active_theme = str_replace( ' ', '', strtolower( $active_theme ) );
2779: return apply_filters( 'epl_active_theme', $active_theme );
2780: }
2781:
2782: /**
2783: * Returns active theme name as a css class with prefix for use in default
2784: * templates
2785: *
2786: * @return mixed|void
2787: * @since 2.1.2
2788: */
2789: function epl_get_active_theme_name() {
2790: $epl_class_prefix = apply_filters( 'epl_active_theme_prefix', 'epl-active-theme-' );
2791: $active_theme = epl_get_active_theme();
2792: return apply_filters( 'epl_active_theme_name', $epl_class_prefix . $active_theme );
2793: }
2794:
2795: /**
2796: * Returns core shortcode names
2797: *
2798: * @return array
2799: * @since 3.3
2800: * @since 3.4.44 Added epl_get_shortcode_list filter.
2801: */
2802: function epl_get_shortcode_list() {
2803: return apply_filters(
2804: 'epl_get_shortcode_list',
2805: array(
2806: 'listing',
2807: 'listing_category',
2808: 'listing_open',
2809: 'listing_feature',
2810: 'listing_location',
2811: 'listing_auction',
2812: 'listing_advanced',
2813: )
2814: );
2815: }
2816:
2817: /**
2818: * Wrapper for wp_doing_ajax with fallback for lower WP versions
2819: *
2820: * @return bool True if it's an ajax request
2821: * @since 3.4.17
2822: */
2823: function epl_wp_doing_ajax() {
2824:
2825: if ( function_exists( 'wp_doing_ajax' ) ) {
2826: return wp_doing_ajax();
2827: } else {
2828: return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
2829: }
2830: }
2831:
2832: /**
2833: * Pagination fix for home
2834: *
2835: * @param WP_Query $query The query.
2836: *
2837: * @since 2.1.2
2838: * @since 3.3 Revised.
2839: */
2840: function epl_home_pagination_fix( $query ) {
2841:
2842: global $wp_query;
2843: $queried_post_type = isset( $query->query_vars['post_type'] ) ? (array) $query->query_vars['post_type'] : array();
2844: $diff = array_diff( $queried_post_type, epl_get_core_post_types() );
2845:
2846: if ( isset( $wp_query->query['paged'] ) && 0 === count( $diff ) ) {
2847: $query->set( 'paged', $wp_query->query['paged'] );
2848: }
2849:
2850: $shortcodes = epl_get_shortcode_list();
2851:
2852: if ( $query->get( 'is_epl_shortcode' ) &&
2853: in_array( $query->get( 'epl_shortcode_name' ), $shortcodes, true ) && ! epl_wp_doing_ajax() ) {
2854:
2855: if ( isset( $_GET['pagination_id'] ) && $_GET['pagination_id'] === $query->get( 'instance_id' ) ) {
2856: $query->set( 'paged', $query->get( 'paged' ) );
2857: } else {
2858: $query->set( 'paged', 1 );
2859: }
2860: }
2861: }
2862: add_action( 'pre_get_posts', 'epl_home_pagination_fix', 99 );
2863:
2864: /**
2865: * Returns status class
2866: *
2867: * @since 2.1.10
2868: */
2869: function epl_property_widget_status_class() {
2870: global $property;
2871: echo 'epl-widget-status-' . esc_attr( $property->get_property_meta( 'property_status' ) );
2872: }
2873: add_action( 'epl_property_widget_status_class', 'epl_property_widget_status_class' );
2874:
2875: /**
2876: * Ability to hide map on single listings
2877: *
2878: * @since 2.1.8
2879: */
2880: function epl_hide_map_from_front() {
2881: $epl_posts = epl_get_active_post_types();
2882: $epl_posts = array_keys( $epl_posts );
2883:
2884: global $post, $property;
2885:
2886: if ( is_single() && in_array( $post->post_type, $epl_posts, true ) ) {
2887:
2888: $hide_map = get_post_meta( $post->ID, 'property_address_hide_map', true );
2889: if ( 'yes' === $hide_map ) {
2890: remove_all_actions( 'epl_property_map' );
2891: }
2892: }
2893: }
2894: add_action( 'wp', 'epl_hide_map_from_front', 10 );
2895:
2896: /**
2897: * Disable paging on listing widget
2898: *
2899: * @since 2.1.8
2900: *
2901: * @param WP_Query $query The query.
2902: */
2903: function epl_nopaging( $query ) {
2904: $restrict_paging = $query->get( 'epl_nopaging' );
2905: if ( true === $restrict_paging ) {
2906: $query->set( 'paged', 1 );
2907: }
2908: }
2909: add_action( 'pre_get_posts', 'epl_nopaging' );
2910:
2911: /**
2912: * Ability to hide author box on single listings
2913: *
2914: * @since 2.1.11
2915: */
2916: function epl_hide_author_box_from_front() {
2917: $epl_posts = epl_get_active_post_types();
2918: $epl_posts = array_keys( $epl_posts );
2919:
2920: global $post, $property;
2921:
2922: if ( is_single() && in_array( $post->post_type, $epl_posts, true ) ) {
2923:
2924: $hide_author_box = get_post_meta( $post->ID, 'property_agent_hide_author_box', true );
2925: if ( 'yes' === $hide_author_box ) {
2926: remove_all_actions( 'epl_single_author' );
2927: }
2928: }
2929: }
2930: add_action( 'wp', 'epl_hide_author_box_from_front', 10 );
2931:
2932: /**
2933: * Retain user grid/list view
2934: *
2935: * @since 2.1.11
2936: */
2937: function epl_update_default_view() {
2938:
2939: $view = isset( $_POST['view'] ) ? sanitize_text_field( wp_unslash( $_POST['view'] ) ) : '';
2940:
2941: if ( in_array( $view, array( 'list', 'grid' ), true ) ) {
2942:
2943: setcookie( 'preferredView', $view, 0, '/' );
2944: }
2945: wp_die( 'success' );
2946: }
2947: add_action( 'wp_ajax_epl_update_default_view', 'epl_update_default_view' );
2948: add_action( 'wp_ajax_nopriv_epl_update_default_view', 'epl_update_default_view' );
2949:
2950: /**
2951: * Custom the_content filter
2952: *
2953: * @since 2.2
2954: * @since 3.4.35 Added support for WP blocks rendering
2955: */
2956: function epl_the_content_filters() {
2957:
2958: if ( ! has_filter( 'epl_get_the_content', 'wptexturize' ) ) {
2959:
2960: add_filter( 'epl_get_the_content', 'wptexturize' );
2961: add_filter( 'epl_get_the_content', 'convert_smilies' );
2962: add_filter( 'epl_get_the_content', 'convert_chars' );
2963: add_filter( 'epl_get_the_content', 'wpautop' );
2964: add_filter( 'epl_get_the_content', 'shortcode_unautop' );
2965: add_filter( 'epl_get_the_content', 'prepend_attachment' );
2966: $vidembed = new WP_Embed();
2967: add_filter( 'epl_get_the_content', array( &$vidembed, 'run_shortcode' ), 8 );
2968: add_filter( 'epl_get_the_content', array( &$vidembed, 'autoembed' ), 8 );
2969: add_filter( 'epl_get_the_content', 'do_shortcode', 11 );
2970: add_filter( 'epl_get_the_content', 'do_blocks', 11 );
2971: }
2972:
2973: add_filter( 'epl_get_the_excerpt', 'epl_trim_excerpt' );
2974: }
2975: add_action( 'init', 'epl_the_content_filters', 1 );
2976:
2977: /**
2978: * Disable property-box left and right class
2979: *
2980: * @since 2.2
2981: */
2982: function epl_compatibility_archive_class_callback() {
2983: $class = '-disable';
2984: echo esc_attr( $class );
2985: }
2986:
2987: /**
2988: * Apply I'm feeling lucky theme options
2989: *
2990: * @since 2.2
2991: */
2992: function epl_apply_feeling_lucky_config() {
2993:
2994: global $epl_settings;
2995:
2996: $epl_posts = epl_get_active_post_types();
2997: $epl_posts = array_keys( $epl_posts );
2998:
2999: // remove epl featured image on single pages in lucky mode.
3000: if ( 'on' === epl_get_option( 'epl_lucky_disable_single_thumb' ) ) {
3001:
3002: if ( is_single() && in_array( get_post_type(), $epl_posts, true ) ) {
3003: remove_all_actions( 'epl_property_featured_image' );
3004: }
3005: }
3006:
3007: // remove active theme's featured image on single pages in lucky mode.
3008: if ( 'on' === epl_get_option( 'epl_lucky_disable_theme_single_thumb' ) ) {
3009:
3010: if ( is_single() && in_array( get_post_type(), $epl_posts, true ) ) {
3011: add_filter( 'post_thumbnail_html', 'epl_remove_single_thumbnail', 20, 5 );
3012: }
3013: }
3014:
3015: // remove featured image on archive pages in lucky mode.
3016: if ( 'on' === epl_get_option( 'epl_lucky_disable_archive_thumb' ) ) {
3017:
3018: if ( is_post_type_archive( $epl_posts ) ) {
3019: add_filter( 'post_thumbnail_html', 'epl_remove_archive_thumbnail', 20, 5 );
3020: }
3021: }
3022:
3023: // remove epl featured image on archive pages in lucky mode.
3024: if ( 'on' === epl_get_option( 'epl_lucky_disable_epl_archive_thumb' ) ) {
3025:
3026: if ( is_post_type_archive( $epl_posts ) ) {
3027: remove_all_actions( 'epl_property_archive_featured_image' );
3028:
3029: // Adds class to disable property-box right and left.
3030: add_action( 'epl_compatibility_archive_class', 'epl_compatibility_archive_class_callback' );
3031: }
3032: }
3033: }
3034: add_action( 'wp', 'epl_apply_feeling_lucky_config', 1 );
3035:
3036: /**
3037: * A workaround to avoid duplicate thumbnails for single listings being
3038: * displayed on archive pages via theme & epl attempts to null the post
3039: * thumbnail image called from theme & display thumbnail image called from epl
3040: *
3041: * @param string $html The html.
3042: * @param string $post_id The post identifier.
3043: * @param string $post_thumbnail_id The post thumbnail identifier.
3044: * @param string $size The size.
3045: * @param string $attr The attribute.
3046: * @return null
3047: *
3048: * @since 2.2
3049: */
3050: function epl_remove_archive_thumbnail( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
3051:
3052: if ( is_admin() ) {
3053: return $html;
3054: }
3055:
3056: if ( is_epl_post_archive() ) { //phpcs:ignore
3057: // Allow archive listing images as well as widget images.
3058: if ( //phpcs:ignore
3059: doing_action( 'epl_property_archive_featured_image' ) ||
3060: doing_action( 'epl_property_widgets_featured_image' ) ||
3061: doing_action( 'epl_author_thumbnail' ) ||
3062: doing_action( 'epl_author_widget_thumbnail' )
3063: ) {
3064:
3065: } else {
3066: $html = '';
3067: }
3068: }
3069:
3070: return $html;
3071: }
3072:
3073: /**
3074: * A workaround to avoid duplicate thumbnails for single listings
3075: *
3076: * @since 2.2
3077: *
3078: * @param string $html The html.
3079: * @param string $post_id The post identifier.
3080: * @param string $post_thumbnail_id The post thumbnail identifier.
3081: * @param string $size The size.
3082: * @param string $attr The attribute.
3083: *
3084: * @return string ( description_of_the_return_value )
3085: */
3086: function epl_remove_single_thumbnail( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
3087:
3088: if ( is_admin() ) {
3089: return $html;
3090: }
3091:
3092: if ( is_epl_post() ) {
3093: // Allow single listing images as well as widget images.
3094: if ( doing_action( 'epl_property_featured_image' ) || doing_action( 'epl_property_widgets_featured_image' ) ) { //phpcs:ignore
3095:
3096: } else {
3097: $html = '';
3098: }
3099: }
3100: return $html;
3101: }
3102:
3103: /**
3104: * Custom property the_content
3105: *
3106: * @since 2.2
3107: */
3108: function epl_the_content() {
3109:
3110: global $property;
3111: $content = apply_filters( 'epl_get_the_content', get_the_content() );
3112: echo str_replace( ']]>', ']]&gt;', $content ); //phpcs:ignore
3113: }
3114: add_action( 'epl_property_the_content', 'epl_the_content' );
3115:
3116: /**
3117: * Custom property the_content
3118: *
3119: * @param string $content The content.
3120: *
3121: * @return false|string
3122: *
3123: * @since 2.2
3124: * @since 3.4.45 Fix: Compatibility mode accidentally styling in admin area.
3125: */
3126: function epl_feeling_lucky( $content ) {
3127:
3128: global $epl_settings;
3129:
3130: if ( is_admin() ) {
3131: return $content;
3132: }
3133:
3134: if ( ! isset( $epl_settings['epl_feeling_lucky'] ) || 'on' !== $epl_settings['epl_feeling_lucky'] ) {
3135: return $content;
3136: }
3137:
3138: $epl_posts = epl_get_active_post_types();
3139: $epl_posts = array_keys( $epl_posts );
3140:
3141: if ( is_single() && in_array( get_post_type(), $epl_posts, true ) ) {
3142: ob_start();
3143: do_action( 'epl_property_single' );
3144: return ob_get_clean();
3145: } elseif ( is_post_type_archive( $epl_posts ) ) {
3146: ob_start();
3147: do_action( 'epl_property_blog' );
3148: /**
3149: * Using return VS echo resolves issues with Yoast SEO repeating content in some cases but breaks the template loading correctly in compatibility mode.
3150: */
3151: echo ob_get_clean(); //phpcs:ignore
3152:
3153: } else {
3154: return $content;
3155: }
3156: }
3157:
3158: add_filter( 'the_content', 'epl_feeling_lucky' );
3159:
3160: /**
3161: * Custom property the_excerpt
3162: *
3163: * @since 2.2
3164: *
3165: * @param string $text The text.
3166: *
3167: * @return mixed|void
3168: */
3169: function epl_trim_excerpt( $text = '' ) {
3170:
3171: $raw_excerpt = $text;
3172: if ( empty( $text ) ) {
3173: $text = get_the_content( '' );
3174:
3175: $text = strip_shortcodes( $text );
3176:
3177: $text = apply_filters( 'epl_get_the_content', $text );
3178: $text = str_replace( ']]>', ']]&gt;', $text );
3179:
3180: $excerpt_length = apply_filters( 'excerpt_length', 55 );
3181: $excerpt_more = apply_filters( 'excerpt_more', ' [&hellip;]' );
3182: $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
3183:
3184: }
3185: return apply_filters( 'epl_trim_excerpt', $text, $raw_excerpt );
3186: }
3187:
3188: /**
3189: * Custom property the_excerpt
3190: *
3191: * @since 2.2
3192: */
3193: function epl_the_excerpt() {
3194: echo wp_kses_post( apply_filters( 'epl_the_excerpt', epl_get_the_excerpt() ) );
3195: }
3196:
3197: /**
3198: * Custom property the_excerpt
3199: *
3200: * @param string $post The post content.
3201: *
3202: * @return mixed|string|void
3203: *
3204: * @since 2.2
3205: * @since 3.4.46 Fix: Support for arguments when in theme compatibility mode and using the_excerpt.
3206: */
3207: function epl_get_the_excerpt( $post = null ) {
3208:
3209: if ( is_bool( $post ) ) {
3210: _deprecated_argument( __FUNCTION__, '2.3' );
3211: }
3212:
3213: if ( $post instanceof WP_Post ) {
3214: $post = get_post( $post );
3215: } else {
3216: $post = get_post();
3217: }
3218:
3219: if ( empty( $post ) ) {
3220: return '';
3221: }
3222:
3223: if ( post_password_required() ) {
3224: return esc_html__( 'There is no excerpt because this is a protected post.', 'easy-property-listings' );
3225: }
3226:
3227: return apply_filters( 'epl_get_the_excerpt', $post->post_excerpt );
3228: }
3229:
3230: /**
3231: * Syntax Highlighter
3232: *
3233: * @since 2.2
3234: *
3235: * @param string $str The string.
3236: * @param string $classname The class.
3237: *
3238: * @return string
3239: */
3240: function epl_syntax_highlight( $str = '', $classname = '' ) {
3241: return '<pre><code class="' . $classname . '">' . htmlentities( $str, ENT_QUOTES, 'UTF-8' ) . '</code></pre>';
3242: }
3243:
3244: /**
3245: * Strip Tags
3246: *
3247: * @param string $value the value.
3248: * @param string $allowed_tags allowed tags.
3249: *
3250: * @return array|string
3251: *
3252: * @since 2.2
3253: */
3254: function epl_strip_tags( $value, $allowed_tags = '' ) {
3255:
3256: if ( ! is_array( $value ) ) {
3257: return strip_tags( $value, $allowed_tags );
3258: }
3259: return $value;
3260: }
3261:
3262: /**
3263: * Esc Attr
3264: *
3265: * @param string $value The value.
3266: * @return string|void
3267: *
3268: * @since 2.2.0
3269: * @since 3.4.23 Fix security function check from array to string.
3270: */
3271: function epl_esc_attr( $value ) {
3272:
3273: if ( is_string( $value ) ) {
3274: return esc_attr( $value );
3275: }
3276: return $value;
3277: }
3278:
3279: /**
3280: * Post Count
3281: *
3282: * @param string $type The type.
3283: * @param string $meta_key The meta key.
3284: * @param string $meta_value The meta value.
3285: * @param string $author_id The author identifier.
3286: *
3287: * @return null
3288: *
3289: * @since 2.2.0
3290: * @since 3.4.38 PHP 8.0 fix.
3291: * @since 3.5.29 Fix: SQL injection. Post types are limited to registered ones and passed as prepared placeholders.
3292: * @since 3.6 Fix: Slow query. The second agent meta is only joined when counting an author's listings, on the property_second_agent key, instead of every meta row of every listing.
3293: */
3294: function epl_get_post_count( $type, $meta_key, $meta_value, $author_id = '' ) {
3295: global $wpdb;
3296:
3297: $where = array( "p.post_status = 'publish'" );
3298: $prepare_args = array();
3299:
3300: if ( empty( $type ) ) {
3301: $epl_posts = array_keys( epl_get_active_post_types() );
3302:
3303: if ( empty( $epl_posts ) ) {
3304: $epl_posts = epl_get_core_post_types();
3305: }
3306:
3307: $placeholders = implode( ', ', array_fill( 0, count( $epl_posts ), '%s' ) );
3308: $where[] = "p.post_type IN ( {$placeholders} )";
3309: $prepare_args = array_merge( $prepare_args, array_values( $epl_posts ) );
3310: } else {
3311: $where[] = 'p.post_type = %s';
3312: $prepare_args[] = $type;
3313: }
3314:
3315: if ( ! empty( $author_id ) ) {
3316: $author_id = absint( $author_id );
3317: $user_info = get_userdata( $author_id );
3318: $user_login = $user_info ? $user_info->user_login : '';
3319:
3320: $where[] = '( p.post_author = %d OR pm2.meta_value = %s )';
3321: $prepare_args[] = $author_id;
3322: $prepare_args[] = $user_login;
3323: }
3324:
3325: $where[] = 'p.ID = pm.post_id';
3326: $where[] = 'pm.meta_key = %s';
3327: $prepare_args[] = $meta_key;
3328: $where[] = 'pm.meta_value = %s';
3329: $prepare_args[] = $meta_value;
3330:
3331: // The second agent is only joined when counting an author's listings, on its own key.
3332: // Joining every meta row of every listing made this count slow.
3333: $second_agent_join = empty( $author_id ) ? '' : "LEFT JOIN {$wpdb->postmeta} pm2 ON ( p.ID = pm2.post_id AND pm2.meta_key = 'property_second_agent' )";
3334:
3335: $sql = "
3336: SELECT count( Distinct p.ID ) AS count
3337: FROM {$wpdb->posts} AS p
3338: INNER JOIN {$wpdb->postmeta} pm ON (p.ID = pm.post_id)
3339: {$second_agent_join}
3340: WHERE " . implode( ' AND ', $where );
3341:
3342: $count = $wpdb->get_row( $wpdb->prepare( $sql, $prepare_args ) ); //phpcs:ignore
3343: return $count->count;
3344: }
3345:
3346: /**
3347: * Get the inspection date format
3348: *
3349: * @since 3.3
3350: *
3351: * @return string
3352: */
3353: function epl_get_inspection_date_format() {
3354:
3355: $date_format = epl_get_option( 'inspection_date_format' ) === 'custom_inspection_date_format' ?
3356: epl_get_option( 'custom_inspection_date_format' ) : epl_get_option( 'inspection_date_format' );
3357:
3358: if ( empty( $date_format ) ) {
3359: $date_format = 'd-M-Y';
3360: }
3361:
3362: return apply_filters( 'epl_inspection_date_format', $date_format );
3363: }
3364:
3365: /**
3366: * Get the inspection time format
3367: *
3368: * @since 3.3
3369: *
3370: * @return string
3371: */
3372: function epl_get_inspection_time_format() {
3373:
3374: $time_format = 'custom_inspection_time_format' === epl_get_option( 'inspection_time_format' ) ?
3375: epl_get_option( 'custom_inspection_time_format' ) : epl_get_option( 'inspection_time_format' );
3376:
3377: if ( empty( $time_format ) ) {
3378: $time_format = 'h:i A';
3379: }
3380:
3381: return apply_filters( 'epl_inspection_time_format', $time_format );
3382: }
3383:
3384: /**
3385: * Inspection Format
3386: *
3387: * @since 2.2
3388: *
3389: * @param string $inspection_date The inspection date.
3390: *
3391: * @return string
3392: */
3393: function epl_inspection_format( $inspection_date ) {
3394:
3395: $formatted_date = '';
3396: $inspection_date = explode( ' ', $inspection_date );
3397:
3398: $date_format = epl_get_inspection_date_format();
3399: $time_format = epl_get_inspection_time_format();
3400:
3401: $date = isset( $inspection_date[0] ) ? gmdate( $date_format, strtotime( $inspection_date[0] ) ) : '';
3402: $time_start = isset( $inspection_date[1] ) ? gmdate( $time_format, strtotime( $inspection_date[1] ) ) : '';
3403: $time_end = isset( $inspection_date[3] ) ? gmdate( $time_format, strtotime( $inspection_date[3] ) ) : '';
3404:
3405: return "{$date} {$time_start} to {$time_end}";
3406: }
3407: add_action( 'epl_inspection_format', 'epl_inspection_format' );
3408:
3409: /**
3410: * Counts the total number of contacts.
3411: *
3412: * @access public
3413: * @since 3.0
3414: *
3415: * @return int - The total number of contacts.
3416: */
3417: function epl_count_total_contacts() {
3418: $counts = wp_count_posts( 'epl_contact' );
3419: return $counts->publish;
3420: }
3421:
3422: /**
3423: * The comment_agent labels EPL saves on contact notes and activities.
3424: *
3425: * Contact notes, calls, emails and other activities are stored as comments on
3426: * the listing they relate to. They are private CRM records, never comments.
3427: *
3428: * @return array
3429: * @since 3.6 Added so every check uses the same labels: 'easy-property-listings' since 3.0, 'epl' on older notes.
3430: */
3431: function epl_contact_note_agents() {
3432: return array( 'easy-property-listings', 'epl' );
3433: }
3434:
3435: /**
3436: * Is this comment an EPL contact note or activity?
3437: *
3438: * @param WP_Comment|object $comment The comment.
3439: *
3440: * @return bool
3441: * @since 3.6 Added.
3442: */
3443: function epl_is_contact_note( $comment ) {
3444: return isset( $comment->comment_agent ) && in_array( $comment->comment_agent, epl_contact_note_agents(), true );
3445: }
3446:
3447: /**
3448: * Can the current request see contact notes in comment lists?
3449: *
3450: * Staff in wp-admin can. Everywhere else (the front end, feeds, the REST API,
3451: * visitors' AJAX requests) contact notes are left out.
3452: *
3453: * @return bool
3454: * @since 3.6 Added.
3455: */
3456: function epl_can_see_contact_notes() {
3457: return is_admin() && current_user_can( 'edit_posts' );
3458: }
3459:
3460: /**
3461: * Hide contacts notes from showing on frontend
3462: *
3463: * @param array $comments The comments.
3464: * @param string $post_id The post identifier.
3465: *
3466: * @return array
3467: * @since 3.0
3468: * @since 3.6 Fix: matched only the old 'epl' label, so notes saved as 'easy-property-listings' were not hidden.
3469: */
3470: function epl_filter_listing_comments_array( $comments, $post_id ) {
3471: foreach ( $comments as $key => $comment ) {
3472: if ( epl_is_contact_note( $comment ) ) {
3473: unset( $comments[ $key ] );
3474: }
3475: }
3476: return $comments;
3477: }
3478: add_filter( 'comments_array', 'epl_filter_listing_comments_array', 10, 2 );
3479:
3480: /**
3481: * SQL that leaves EPL contact notes out of a comment query.
3482: *
3483: * @return string
3484: * @since 3.6 Added.
3485: */
3486: function epl_exclude_contact_notes_sql() {
3487: global $wpdb;
3488:
3489: $agents = epl_contact_note_agents();
3490: $placeholders = implode( ', ', array_fill( 0, count( $agents ), '%s' ) );
3491:
3492: // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
3493: return $wpdb->prepare( " AND {$wpdb->comments}.comment_agent NOT IN ( $placeholders )", $agents );
3494: }
3495:
3496: /**
3497: * Leave contact notes out of comment queries outside wp-admin.
3498: *
3499: * Covers comment lists, the Recent Comments widget and the REST API. EPL's own
3500: * contact screens ask for notes by contact (meta key epl_contact_id) and still get them.
3501: *
3502: * @param array $clauses The query clauses.
3503: * @param WP_Comment_Query $query The comment query.
3504: *
3505: * @return array
3506: * @since 3.6 Added: contact notes and activities showed in public comment lists.
3507: */
3508: function epl_hide_contact_notes_from_comment_queries( $clauses, $query ) {
3509: $asks_for_a_contacts_notes = isset( $query->query_vars['meta_key'] ) && 'epl_contact_id' === $query->query_vars['meta_key'];
3510:
3511: if ( epl_can_see_contact_notes() || $asks_for_a_contacts_notes ) {
3512: return $clauses;
3513: }
3514:
3515: $clauses['where'] .= epl_exclude_contact_notes_sql();
3516: return $clauses;
3517: }
3518: add_filter( 'comments_clauses', 'epl_hide_contact_notes_from_comment_queries', 10, 2 );
3519:
3520: /**
3521: * Leave contact notes out of the comment RSS feeds.
3522: *
3523: * @param string $where The feed's WHERE clause.
3524: *
3525: * @return string
3526: * @since 3.6 Added: contact notes and activities showed in the comment feeds.
3527: */
3528: function epl_hide_contact_notes_from_comment_feeds( $where ) {
3529: return $where . epl_exclude_contact_notes_sql();
3530: }
3531: add_filter( 'comment_feed_where', 'epl_hide_contact_notes_from_comment_feeds' );
3532:
3533: /**
3534: * Archive Page Title
3535: *
3536: * @return void the archive title
3537: *
3538: * @since 3.0.0
3539: * @since 3.5.2 Added filter epl_archive_title to alter archive title.
3540: * @since 3.5.14 Corrected escaping function to esc_html.
3541: */
3542: function epl_archive_title_callback() {
3543: the_post();
3544:
3545: if ( is_tax() && function_exists( 'epl_is_search' ) && false === epl_is_search() ) { // Tag Archive.
3546: $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
3547: // Translators: term name.
3548: $title = sprintf( __( 'Property in %s', 'easy-property-listings' ), $term->name );
3549: } elseif ( function_exists( 'epl_is_search' ) && epl_is_search() ) { // Search Result.
3550: $title = apply_filters( 'epl_archive_title_search_result', __( 'Search Result', 'easy-property-listings' ) );
3551: } elseif ( function_exists( 'is_post_type_archive' ) && is_post_type_archive() && function_exists( 'post_type_archive_title' ) ) { // Post Type Archive.
3552: $title = post_type_archive_title( '', false );
3553: $title = apply_filters( 'epl_archive_title_post_type', $title );
3554: } else { // Default catchall just in case.
3555: $title = apply_filters( 'epl_archive_title_fallback', __( 'Listing', 'easy-property-listings' ) );
3556: }
3557:
3558: if ( is_paged() ) {
3559: // Translators: title, page number.
3560: printf( '%s &ndash; Page %d', esc_html( $title ), esc_attr( get_query_var( 'paged' ) ) );
3561: } else {
3562: echo wp_kses_post( apply_filters( 'epl_archive_title_default', $title ) );
3563: }
3564:
3565: rewind_posts();
3566: }
3567: add_action( 'epl_the_archive_title', 'epl_archive_title_callback' );
3568:
3569: /**
3570: * Shortcode Sorter
3571: *
3572: * @param array $args The arguments.
3573: * @param string $type The type.
3574: * @param string $name The name.
3575: *
3576: * @return array $args
3577: *
3578: * @since 3.0
3579: * @since 3.4.44 Option sortby based on instance_id now.
3580: * @since 3.6 Sorting has tiebreakers (epl_get_sorter_query_args()), so listings with the same value don't repeat or go missing across pages.
3581: */
3582: function epl_add_orderby_args( $args, $type = '', $name = '' ) {
3583:
3584: if ( 'shortcode' === $type ) {
3585: $args['is_epl_shortcode'] = true;
3586: $args['epl_shortcode_name'] = $name;
3587: }
3588:
3589: $post_type = isset( $args['post_type'] ) ? current( $args['post_type'] ) : '';
3590: $post_type = sanitize_text_field( wp_unslash( $post_type ) );
3591: $orderby = isset( $_GET['sortby'] ) ? sanitize_text_field( wp_unslash( $_GET['sortby'] ) ) : '';
3592:
3593: $instance_id = ! empty( $args['instance_id'] ) ? sanitize_text_field( $args['instance_id'] ) : '';
3594: $set_instance_id = '';
3595:
3596: if ( ! empty( $_GET['instance_id'] ) ) {
3597: $set_instance_id = sanitize_text_field( wp_unslash( $_GET['instance_id'] ) );
3598: }
3599:
3600: if ( ! empty( $orderby ) && ( ! empty( $instance_id ) && $instance_id === $set_instance_id ) ) {
3601:
3602: $sorters = epl_sorting_options( $post_type );
3603:
3604: foreach ( $sorters as $sorter ) {
3605:
3606: if ( $orderby === $sorter['id'] ) {
3607:
3608: $args = array_merge( $args, epl_get_sorter_query_args( $sorter ) );
3609: break;
3610: }
3611: }
3612: }
3613: return $args;
3614: }
3615:
3616: /**
3617: * Shortcode Results Not Found Message
3618: *
3619: * @param string $shortcode The shortcode.
3620: *
3621: * @since 3.1.5
3622: * @since 3.4.48 Added new class for the message removed incorrect class name.
3623: * @since 3.5 Tweak: Shortcode results message allow basic html.
3624: * @since 3.6 The title filters receive the shortcode. New epl_shortcode_results_message_text filter adds a line under the title (empty by default, so output is unchanged) and epl_shortcode_results_message_html filters the whole message.
3625: */
3626: function epl_shortcode_results_message_callback( $shortcode = 'default' ) {
3627:
3628: $title = apply_filters( 'epl_shortcode_results_message_title', __( 'Nothing found, please check back later.', 'easy-property-listings' ), $shortcode );
3629:
3630: if ( 'open' === $shortcode ) {
3631: $title = apply_filters( 'epl_shortcode_results_message_title_open', __( 'Nothing currently scheduled for inspection, please check back later.', 'easy-property-listings' ), $shortcode );
3632: }
3633:
3634: $text = apply_filters( 'epl_shortcode_results_message_text', '', $shortcode );
3635:
3636: $html = '<h3 class="epl-alert epl-shortcode-results-message epl-shortcode-results-message-' . esc_attr( $shortcode ) . '">' . wp_kses_post( $title ) . '</h3>';
3637:
3638: if ( '' !== (string) $text ) {
3639: $html .= '<p class="epl-shortcode-results-message-text epl-shortcode-results-message-text-' . esc_attr( $shortcode ) . '">' . wp_kses_post( $text ) . '</p>';
3640: }
3641:
3642: echo wp_kses_post( apply_filters( 'epl_shortcode_results_message_html', $html, $shortcode, $title, $text ) );
3643: }
3644: add_action( 'epl_shortcode_results_message', 'epl_shortcode_results_message_callback' );
3645:
3646: /**
3647: * Search Not Found Messages
3648: *
3649: * @since 3.1.8
3650: * @since 3.4.33 Tweak: Search results not found filter epl_property_search_not_found_title allows basic html to be passed.
3651: * @since 3.4.48 Container added to search not found.
3652: */
3653: function epl_property_search_not_found_callback() {
3654:
3655: $title = apply_filters( 'epl_property_search_not_found_title', __( 'Listing not Found', 'easy-property-listings' ) );
3656: $message = apply_filters( 'epl_property_search_not_found_message', __( 'Listing not found, expand your search criteria and try again.', 'easy-property-listings' ) );
3657:
3658: ?>
3659: <div class="epl-search-not-found">
3660: <div class="epl-search-not-found-title entry-header clearfix">
3661: <h3 class="entry-title"><?php echo wp_kses_post( $title ); ?></h3>
3662: </div>
3663:
3664: <div class="epl-search-not-found-message entry-content clearfix">
3665: <p><?php echo wp_kses_post( $message ); ?></p>
3666: </div>
3667: </div>
3668:
3669: <?php
3670: }
3671: add_action( 'epl_property_search_not_found', 'epl_property_search_not_found_callback' );
3672:
3673: /**
3674: * Add Listing Status and Under Offer to Post Class
3675: *
3676: * @param array $classes The classes.
3677: *
3678: * @return array
3679: *
3680: * @since 3.1.16
3681: * @since 3.4.23 Added compatibility class.
3682: * @since 3.6 Added epl-status-auction for listings with an auction authority (commercial uses the commercial authority).
3683: */
3684: function epl_property_post_class_listing_status_callback( $classes ) {
3685:
3686: if ( is_epl_post() ) {
3687:
3688: $property_status = get_property_meta( 'property_status' );
3689: $property_under_offer = get_property_meta( 'property_under_offer' );
3690: $commercial_type = get_property_meta( 'property_com_listing_type' );
3691: $authority = 'commercial' === get_post_type() ? get_property_meta( 'property_com_authority' ) : get_property_meta( 'property_authority' );
3692: $class_prefix = 'epl-status-';
3693:
3694: if ( ! empty( $property_status ) ) {
3695: $classes[] = $class_prefix . strtolower( $property_status );
3696: }
3697: if ( 'yes' === $property_under_offer && 'sold' !== $property_status ) {
3698: $classes[] = $class_prefix . 'under-offer';
3699: }
3700: if ( 'auction' === $authority ) {
3701: $classes[] = $class_prefix . 'auction';
3702: }
3703: if ( ! empty( $commercial_type ) ) {
3704: $class_prefix = 'epl-commercial-type-';
3705: $classes[] = $class_prefix . strtolower( $commercial_type );
3706: }
3707: }
3708:
3709: if ( 'on' === epl_get_option( 'epl_feeling_lucky', 'off' ) && is_epl_post_archive() ) {
3710: $classes[] = 'epl-property-blog-compatibility';
3711: }
3712:
3713: return $classes;
3714: }
3715: add_filter( 'post_class', 'epl_property_post_class_listing_status_callback' );
3716:
3717: /**
3718: * Get the author loop
3719: *
3720: * @since 3.3
3721: * @since 3.4.38 Support for third & forth listing agents.
3722: */
3723: function epl_archive_author_callback() {
3724: global $epl_author_secondary, $epl_author_third, $epl_author_fourth;
3725: epl_get_template_part( 'content-author-archive-card.php' );
3726:
3727: if ( is_epl_post() ) {
3728: if ( epl_listing_has_secondary_author() ) {
3729: epl_get_template_part( 'content-author-archive-card.php', array( 'epl_author' => $epl_author_secondary ) );
3730: }
3731: if ( epl_listing_has_third_agent() ) {
3732: epl_get_template_part( 'content-author-archive-card', array( 'epl_author' => $epl_author_third ) );
3733: }
3734: if ( epl_listing_has_fourth_agent() ) {
3735: epl_get_template_part( 'content-author-archive-card', array( 'epl_author' => $epl_author_fourth ) );
3736: }
3737: epl_reset_post_author();
3738: }
3739: }
3740: add_action( 'epl_archive_author', 'epl_archive_author_callback' );
3741:
3742: /**
3743: * Check whether the current user can manage contact-capture data.
3744: *
3745: * The contact-capture form is a public lead-capture feature, so this is NOT an
3746: * access gate on the form itself. It is used only to exempt trusted logged-in
3747: * users (agents/admins) from the anti-abuse rate limit applied to anonymous
3748: * submissions. Uses the same configurable capability as the contacts screen.
3749: *
3750: * @return bool
3751: * @since 3.5.25
3752: */
3753: function epl_contact_capture_user_can_manage() {
3754: $capability = epl_get_option( 'min_contact_access', 'manage_options' );
3755: $capability = is_string( $capability ) && ! empty( $capability ) ? $capability : 'manage_options';
3756: $allowed = current_user_can( $capability );
3757:
3758: return apply_filters( 'epl_contact_capture_user_can_manage', $allowed, $capability );
3759: }
3760:
3761: /**
3762: * Resolve the client IP for rate limiting.
3763: *
3764: * Deliberately uses REMOTE_ADDR only (not X-Forwarded-For), which cannot be
3765: * spoofed at the TCP layer and so is the safe default for an abuse control.
3766: *
3767: * @return string Validated IP address, or '' if unavailable.
3768: * @since 3.5.25
3769: */
3770: function epl_contact_capture_get_ip() {
3771: $ip = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
3772: $ip = filter_var( $ip, FILTER_VALIDATE_IP );
3773:
3774: return $ip ? $ip : '';
3775: }
3776:
3777: /**
3778: * Per-IP throttle for anonymous contact-capture submissions.
3779: *
3780: * Blunts the write-amplified spam/DoS vector: an unauthenticated visitor can
3781: * otherwise trigger ~8-10 DB writes per request with unlimited unique emails
3782: * (local+tag@domain). Trusted logged-in users are exempted by the caller.
3783: *
3784: * @return bool True when the current client has exceeded the limit.
3785: * @since 3.5.25
3786: */
3787: function epl_contact_capture_rate_limit_exceeded() {
3788: $max = (int) apply_filters( 'epl_contact_capture_rate_limit_max', 10 );
3789: $window = (int) apply_filters( 'epl_contact_capture_rate_limit_window', 10 * MINUTE_IN_SECONDS );
3790:
3791: // A non-positive max or window disables throttling.
3792: if ( $max <= 0 || $window <= 0 ) {
3793: return false;
3794: }
3795:
3796: $ip = epl_contact_capture_get_ip();
3797: if ( '' === $ip ) {
3798: return false;
3799: }
3800:
3801: $key = 'epl_ccap_rl_' . md5( $ip );
3802: $count = (int) get_transient( $key );
3803:
3804: if ( $count >= $max ) {
3805: return true;
3806: }
3807:
3808: set_transient( $key, $count + 1, $window );
3809:
3810: return false;
3811: }
3812:
3813: /**
3814: * Validate and persist a contact-capture request.
3815: *
3816: * Shared by the AJAX handler and the form builder callback so direct form POSTs
3817: * run through the same validation. This is a public lead-capture feature, so it
3818: * does not require authorization; abuse is bounded by the nonce (CSRF), the
3819: * honeypot, input sanitization, and a per-IP rate limit on anonymous requests.
3820: *
3821: * @param array $request Submitted request data.
3822: * @return true|WP_Error
3823: * @since 3.5.25
3824: */
3825: function epl_process_contact_capture_request( $request ) {
3826: if ( ! is_array( $request ) || ! empty( $request['epl_contact_anti_spam'] ) ) {
3827: return new WP_Error( 'epl_contact_capture_invalid', __( 'There was a problem with your submission.', 'easy-property-listings' ) );
3828: }
3829:
3830: // Throttle anonymous submissions; trusted logged-in users are exempt.
3831: if ( ! epl_contact_capture_user_can_manage() && epl_contact_capture_rate_limit_exceeded() ) {
3832: return new WP_Error( 'epl_contact_capture_throttled', __( 'Too many submissions. Please try again later.', 'easy-property-listings' ) );
3833: }
3834:
3835: $email = isset( $request['epl_contact_email'] ) ? sanitize_email( wp_unslash( $request['epl_contact_email'] ) ) : '';
3836: if ( empty( $email ) ) {
3837: return new WP_Error( 'epl_contact_capture_email_required', __( 'Email is required.', 'easy-property-listings' ) );
3838: }
3839:
3840: if ( ! is_email( $email ) ) {
3841: return new WP_Error( 'epl_contact_capture_invalid_email', __( 'Invalid email.', 'easy-property-listings' ) );
3842: }
3843:
3844: $fname = isset( $request['epl_contact_first_name'] )
3845: ? sanitize_text_field( wp_unslash( $request['epl_contact_first_name'] ) )
3846: : '';
3847:
3848: $lname = isset( $request['epl_contact_last_name'] )
3849: ? sanitize_text_field( wp_unslash( $request['epl_contact_last_name'] ) )
3850: : '';
3851:
3852: $phone = isset( $request['epl_contact_phone'] )
3853: ? sanitize_text_field( wp_unslash( $request['epl_contact_phone'] ) )
3854: : '';
3855:
3856: $title = isset( $request['epl_contact_title'] )
3857: ? sanitize_text_field( wp_unslash( $request['epl_contact_title'] ) )
3858: : '';
3859:
3860: $title = trim( $title );
3861: if ( empty( $title ) && ( $fname || $lname ) ) {
3862: $title = trim( $fname . ' ' . $lname );
3863: }
3864: if ( empty( $title ) ) {
3865: $title = $email;
3866: }
3867:
3868: $contact_listing_id = isset( $request['epl_contact_listing_id'] ) ? absint( $request['epl_contact_listing_id'] ) : 0;
3869: if ( $contact_listing_id ) {
3870: $listing = get_post( $contact_listing_id );
3871: $listing_type = $listing instanceof WP_Post ? $listing->post_type : '';
3872: $valid_types = array_unique( array_merge( array_keys( epl_get_post_types() ), epl_all_post_types() ) );
3873:
3874: if (
3875: ! $listing instanceof WP_Post ||
3876: ! in_array( $listing_type, $valid_types, true )
3877: ) {
3878: return new WP_Error( 'epl_contact_capture_invalid_listing', __( 'Invalid listing.', 'easy-property-listings' ) );
3879: }
3880: }
3881:
3882: $contact_listing_note = isset( $request['epl_contact_note'] )
3883: ? sanitize_textarea_field( wp_unslash( $request['epl_contact_note'] ) )
3884: : '';
3885:
3886: // Always log an activity for the submission so the agent sees the enquiry
3887: // and, when present, the listing it was submitted on.
3888: $activity_note = '' !== $contact_listing_note
3889: ? $contact_listing_note
3890: : __( 'Enquiry submitted via contact form.', 'easy-property-listings' );
3891:
3892: $contact = new EPL_Contact( $email );
3893: if ( ! empty( $contact->ID ) ) {
3894: if ( $contact_listing_id ) {
3895: $contact->attach_listing( $contact_listing_id );
3896: }
3897:
3898: $contact->add_note( $activity_note, 'note', $contact_listing_id );
3899:
3900: return true;
3901: }
3902:
3903: $contact_data = array(
3904: 'name' => $title,
3905: 'email' => $email,
3906: );
3907:
3908: if ( ! $contact->create( $contact_data ) ) {
3909: return new WP_Error( 'epl_contact_capture_create_failed', __( 'There was a problem with your submission.', 'easy-property-listings' ) );
3910: }
3911:
3912: $contact->update_meta( 'contact_first_name', $fname );
3913: $contact->update_meta( 'contact_last_name', $lname );
3914: $contact->update_meta( 'contact_phones', array( 'phone' => $phone ) );
3915: $contact->update_meta( 'contact_category', 'widget' );
3916:
3917: if ( $contact_listing_id ) {
3918: $contact->attach_listing( $contact_listing_id );
3919: }
3920:
3921: $contact->add_note( $activity_note, 'note', $contact_listing_id );
3922:
3923: return true;
3924: }
3925:
3926: /**
3927: * Contact capture action and messages.
3928: *
3929: * @since 3.3
3930: * @since 3.5.16 Fix: Vulnerability in contact form shortcode.
3931: * @since 3.5.17 Tweak: Contact form email address validation check and message.
3932: * @since 3.5.25 Hardened via shared validation, nonce/honeypot and per-IP rate limiting.
3933: */
3934: function epl_contact_capture_action() {
3935:
3936: $success = array(
3937: 'status' => 'success',
3938: 'msg' => apply_filters(
3939: 'epl_contact_capture_success_msg',
3940: __( 'Your enquiry has been submitted.', 'easy-property-listings' )
3941: ),
3942: );
3943:
3944: $fail = array(
3945: 'status' => 'fail',
3946: 'msg' => apply_filters(
3947: 'epl_contact_capture_fail_msg',
3948: __( 'There was a problem with your submission.', 'easy-property-listings' )
3949: ),
3950: );
3951:
3952: if ( false === check_ajax_referer( 'epl_contact_widget', 'epl_contact_widget', false ) ) {
3953: wp_send_json( $fail, 403 );
3954: }
3955:
3956: $result = epl_process_contact_capture_request( $_POST );
3957: if ( is_wp_error( $result ) ) {
3958: $fail['msg'] = $result->get_error_message();
3959: wp_send_json( $fail, 400 );
3960: }
3961:
3962: wp_send_json( $success );
3963: }
3964: add_action( 'wp_ajax_epl_contact_capture_action', 'epl_contact_capture_action' );
3965: add_action( 'wp_ajax_nopriv_epl_contact_capture_action', 'epl_contact_capture_action' );
3966:
3967: /**
3968: * Get Post ID from Unique ID
3969: *
3970: * @param string $unique_id Unique ID.
3971: * @return mixed false if not found, else Post ID
3972: * @since 3.5.0
3973: */
3974: function epl_get_post_id_from_unique_id( $unique_id = '' ) {
3975:
3976: if ( '' === $unique_id ) {
3977: return false;
3978: }
3979:
3980: $args = array(
3981: 'meta_key' => 'property_unique_id',
3982: 'meta_value' => $unique_id,
3983: 'post_type' => epl_get_core_post_types(),
3984: 'post_status' => 'publish',
3985: 'posts_per_page' => -1,
3986: );
3987:
3988: $posts = get_posts( $args );
3989:
3990: if ( ! empty( $posts ) ) {
3991: $post = current( $posts );
3992: return $post->ID;
3993: }
3994:
3995: return false;
3996: }
3997:
3998: /**
3999: * Renders stickers, based on meta values, an alternative to epl_price_stickers.
4000: *
4001: * @param array $options The options.
4002: * @param array $stickers The stickers.
4003: *
4004: * @throws Exception Something.
4005: * @since 3.4.27
4006: */
4007: function epl_stickers( $options = array(), $stickers = array() ) {
4008:
4009: global $post;
4010:
4011: if ( ! is_epl_post() ) {
4012: return;
4013: }
4014:
4015: $default_options = array(
4016: 'wrap' => false,
4017: 'wrap_class' => 'epl-stickers-wrapper',
4018: 'wrapper_tag' => 'div',
4019: 'sticker_tag' => 'span',
4020: 'sticker_class' => 'status-sticker',
4021: 'max_stickers' => 2,
4022: );
4023:
4024: $sticker_counts = 0;
4025:
4026: $options = array_merge( $default_options, $options );
4027:
4028: if ( empty( $stickers ) ) {
4029: $stickers = epl_get_stickers_array();
4030: }
4031:
4032: $options = apply_filters( 'epl_stickers_options', $options );
4033:
4034: if ( $options['wrap'] ) {
4035: echo '<' . esc_attr( $options['wrapper_tag'] ) . ' class="' . esc_attr( $options['wrap_class'] ) . '">';
4036: }
4037:
4038: foreach ( $stickers as $key => $sticker ) {
4039:
4040: if ( $sticker_counts === $default_options['max_stickers'] ) {
4041: break;
4042: }
4043: ?>
4044:
4045: <<?php echo esc_attr( $options['sticker_tag'] ); ?> class="<?php echo esc_attr( $options['sticker_class'] . ' ' . $sticker['class'] ); ?>">
4046: <?php
4047: echo isset( $sticker['before'] ) ?
4048: wp_kses_post( $sticker['before'] ) : '';
4049: echo wp_kses_post( $sticker['label'] );
4050: echo isset( $sticker['after'] ) ?
4051: wp_kses_post( $sticker['after'] ) : '';
4052: ?>
4053: </<?php echo esc_attr( $options['sticker_tag'] ); ?>>
4054: <?php
4055: ++$sticker_counts;
4056: }
4057:
4058: if ( $options['wrap'] ) {
4059: echo '</' . esc_attr( $options['wrapper_tag'] ) . '>';
4060: }
4061: }
4062:
4063: /**
4064: * Returns stickers array based on type, status etc.
4065: *
4066: * @param array $sticker_keys Array of keys.
4067: *
4068: * @return mixed|void
4069: *
4070: * @throws Exception Something.
4071: * @since 3.4.27
4072: * @since 3.4.28 Added array and filter.
4073: */
4074: function epl_get_stickers_array( $sticker_keys = array() ) {
4075:
4076: global $post;
4077:
4078: $stickers = array(
4079:
4080: 'under_offer' => array(
4081: 'conditions' => array(
4082: 'property_status' => 'current',
4083: 'property_under_offer' => array( 'yes' ),
4084: ),
4085: 'type' => epl_get_core_post_types(),
4086: 'label' => epl_get_option( 'label_under_offer' ),
4087: 'before' => '',
4088: 'after' => '',
4089: 'class' => 'under-offer',
4090: ),
4091: 'home_open' => array(
4092: 'conditions' => array(
4093: 'property_inspection_times' => array( null, '' ),
4094: ),
4095: 'compare' => '!=',
4096: 'type' => epl_get_core_post_types(),
4097: 'label' => epl_get_option( 'label_home_open' ),
4098: 'before' => '',
4099: 'after' => '',
4100: 'class' => 'open',
4101: ),
4102:
4103: 'new' => array(
4104: 'type' => epl_get_core_post_types(),
4105: 'label' => epl_get_option( 'label_new' ),
4106: 'before' => '',
4107: 'after' => '',
4108: 'class' => 'new',
4109:
4110: ),
4111: 'rental_lease' => array(
4112: 'conditions' => array(
4113: 'property_status' => 'current',
4114: ),
4115: 'type' => array( 'rental' ),
4116: 'label' => __( 'For Lease', 'easy-property-listings' ),
4117: 'before' => '',
4118: 'after' => '',
4119: 'class' => 'for-lease',
4120: ),
4121: 'leased' => array(
4122: 'conditions' => array(
4123: 'property_status' => 'leased',
4124: ),
4125: 'type' => array( 'rental', 'commercial_land', 'commercial' ),
4126: 'label' => epl_get_option( 'label_leased' ),
4127: 'before' => '',
4128: 'after' => '',
4129: 'class' => 'leased',
4130: ),
4131: 'current_sales' => array(
4132: 'conditions' => array(
4133: 'property_status' => 'current',
4134: ),
4135: 'type' => array( 'property', 'rural', 'land', 'business' ),
4136: 'label' => __( 'For Sale', 'easy-property-listings' ),
4137: 'before' => '',
4138: 'after' => '',
4139: 'class' => 'for-sale',
4140: ),
4141: 'sold' => array(
4142: 'conditions' => array(
4143: 'property_status' => 'sold',
4144: ),
4145: 'type' => epl_get_core_post_types(),
4146: 'label' => epl_get_option( 'label_sold' ),
4147: 'before' => '',
4148: 'after' => '',
4149: 'class' => 'sold',
4150: ),
4151: 'commercial_sale_lease' => array(
4152: 'conditions' => array(
4153: 'property_status' => 'current',
4154: 'property_com_listing_type' => array( 'both' ),
4155: ),
4156: 'type' => array( 'commercial', 'commercial_land' ),
4157: 'label' => __( 'For Sale & Lease', 'easy-property-listings' ),
4158: 'before' => '',
4159: 'after' => '',
4160: 'class' => 'for-sale',
4161: ),
4162: 'commercial_sale' => array(
4163: 'conditions' => array(
4164: 'property_status' => 'current',
4165: 'property_com_listing_type' => array( 'sale' ),
4166: ),
4167: 'type' => array( 'commercial', 'commercial_land' ),
4168: 'label' => __( 'For Sale', 'easy-property-listings' ),
4169: 'before' => '',
4170: 'after' => '',
4171: 'class' => 'for-sale',
4172: ),
4173: 'commercial_lease' => array(
4174: 'conditions' => array(
4175: 'property_status' => 'current',
4176: 'property_com_listing_type' => array( 'lease' ),
4177: ),
4178: 'type' => array( 'commercial', 'commercial_land' ),
4179: 'label' => __( 'For Lease', 'easy-property-listings' ),
4180: 'before' => '',
4181: 'after' => '',
4182: 'class' => 'for-lease',
4183: ),
4184:
4185: );
4186:
4187: /**
4188: * Hook into this array to add / remove stickers based on conditions.
4189: *
4190: * @var callable $stickers
4191: */
4192: $stickers = apply_filters( 'epl_available_stickers', $stickers );
4193:
4194: $return = array();
4195:
4196: foreach ( $stickers as $key => $sticker ) {
4197:
4198: $add_sticker = false;
4199:
4200: if ( ! empty( $sticker_keys ) && ! in_array( $key, $sticker_keys, true ) ) {
4201: continue;
4202: }
4203:
4204: if ( ! empty( $sticker ) && is_array( $sticker ) ) {
4205:
4206: if ( ! in_array( get_post_type(), $sticker['type'], true ) ) {
4207: continue;
4208: }
4209:
4210: if ( 'new' === $key ) {
4211:
4212: $date = new DateTime( $post->post_date );
4213: $now = new DateTime();
4214:
4215: // php > 5.3.
4216: if ( method_exists( $now, 'diff' ) ) {
4217:
4218: $diff = $now->diff( $date );
4219: $diff = $diff->days;
4220: } else {
4221: $diff = strtotime( $now->format( 'M d Y ' ) ) - strtotime( $date->format( 'M d Y ' ) );
4222: $diff = floor( $diff / 3600 / 24 );
4223:
4224: }
4225:
4226: if ( epl_get_option( 'sticker_new_range' ) >= $diff ) {
4227:
4228: $return[ $key ] = array(
4229: 'label' => $sticker['label'],
4230: 'class' => $sticker['class'],
4231: 'before' => $sticker['before'],
4232: 'after' => $sticker['after'],
4233: );
4234: }
4235: } else {
4236:
4237: $conditions = $sticker['conditions'];
4238: $compare = isset( $sticker['compare'] ) ? $sticker['compare'] : '=';
4239:
4240: $add_sticker = epl_sticker_is_condition_valid( $conditions, $compare );
4241:
4242: }
4243:
4244: if ( $add_sticker ) {
4245: $return[ $key ] = array(
4246: 'label' => $sticker['label'],
4247: 'class' => $sticker['class'],
4248: 'before' => $sticker['before'],
4249: 'after' => $sticker['after'],
4250: );
4251: }
4252: }
4253: }
4254:
4255: /**
4256: * List of stickers for current listing, hook here if only need to change labels,
4257: * Class etc. for displayed labels.
4258: */
4259: return apply_filters( 'epl_stickers_array', $return );
4260: }
4261:
4262: /**
4263: * Check if sticker condition is valid.
4264: *
4265: * @param array $condition The condition.
4266: * @param string $compare Comparison.
4267: *
4268: * @return bool
4269: * @since 3.4.28
4270: */
4271: function epl_sticker_is_condition_valid( $condition, $compare = '=' ) {
4272:
4273: $condition_met = 0;
4274: $total_condition = count( $condition );
4275: $match = false;
4276:
4277: foreach ( $condition as $key => $value ) {
4278:
4279: if ( is_array( $value ) ) {
4280:
4281: if ( in_array( get_property_meta( $key ), $value, true ) ) {
4282: ++$condition_met;
4283: }
4284: } else {
4285: if ( get_property_meta( $key ) === $value ) {
4286: ++$condition_met;
4287: }
4288: }
4289: }
4290: $match = $total_condition === $condition_met ? true : false;
4291:
4292: return '=' === $compare ? $match : ! $match;
4293: }
4294:
4295: /**
4296: * Property Status Labels.
4297: *
4298: * @param array $statues The statues.
4299: * @param array $options The options.
4300: *
4301: * @throws Exception Summary.
4302: * @since 3.4.28
4303: */
4304: function epl_property_status( $statues = array(), $options = array() ) {
4305:
4306: $statues_defaults = array(
4307: 'commercial_lease',
4308: 'commercial_sale',
4309: 'rental_lease',
4310: 'leased',
4311: 'sold',
4312: 'current_sales',
4313: 'commercial_sale_lease',
4314: );
4315:
4316: $statues = array_merge( $statues_defaults, (array) $statues );
4317:
4318: $statues = apply_filters( 'epl_property_status_keys', $statues );
4319:
4320: $stickers = epl_get_stickers_array( $statues );
4321:
4322: $default_options = array(
4323: 'wrap' => true,
4324: 'wrap_class' => 'epl-listing-status',
4325: 'wrapper_tag' => 'div',
4326: 'sticker_tag' => 'span',
4327: 'sticker_class' => 'epl-widget-status-label',
4328: );
4329:
4330: $options = array_merge( $default_options, (array) $options );
4331: epl_stickers( $options, $stickers );
4332: }
4333: add_action( 'epl_property_status', 'epl_property_status', 10, 2 );
4334:
4335: /**
4336: * Add Body classes for EPL Single & Archive Pages.
4337: *
4338: * @param array $classes The classes.
4339: *
4340: * @return array $classes Modified classes.
4341: * @since 3.4.29
4342: * @since 3.4.38 Added epl-search-results custom body class for search results.
4343: */
4344: function epl_body_classes( $classes ) {
4345:
4346: if ( is_epl_post_single() ) {
4347: $classes[] = 'epl-single-listing';
4348: $classes[] = 'epl-single-' . get_post_type();
4349: }
4350:
4351: if ( is_epl_post_archive() ) {
4352: $classes[] = 'epl-post-type-archive';
4353: $classes[] = 'epl-post-type-archive-' . get_post_type();
4354: }
4355:
4356: if ( epl_is_search() ) {
4357: $classes[] = 'epl-post-type-archive';
4358: $classes[] = 'epl-search-results';
4359: }
4360:
4361: return $classes;
4362: }
4363: add_filter( 'body_class', 'epl_body_classes', 10 );
4364:
4365: /**
4366: * Get total agent count for listing.
4367: *
4368: * @since 3.5.3
4369: */
4370: function epl_get_total_agent_count() {
4371: $counter = 1;
4372:
4373: $second_agent = get_property_meta( 'property_second_agent' );
4374: $third_agent = get_property_meta( 'property_third_agent' );
4375: $fourth_agent = get_property_meta( 'property_fourth_agent' );
4376: $counter = ! empty( $second_agent ) ? $counter + 1 : $counter;
4377: $counter = ! empty( $third_agent ) ? $counter + 1 : $counter;
4378: $counter = ! empty( $fourth_agent ) ? $counter + 1 : $counter;
4379:
4380: return $counter;
4381: }
4382:
4383: /**
4384: * Helper function to get user ID by login.
4385: *
4386: * @since 3.5.10
4387: *
4388: * @param string $login The login name of the user.
4389: * @return int|false The user ID if found, false otherwise.
4390: */
4391: function epl_get_agent_id_by_login( $login ) {
4392: if ( ! empty( $login ) ) {
4393: $user = get_user_by( 'login', $login );
4394: return $user ? $user->ID : false;
4395: }
4396: return false;
4397: }
4398:
4399: /**
4400: * Get the count of active agents.
4401: *
4402: * @since 3.5.3
4403: * @since 3.5.10 Fix: blank agents.
4404: *
4405: * @return int The count of unique active agents.
4406: */
4407: function epl_get_active_agent_count() {
4408: global $epl_author;
4409:
4410: $agents = array( $epl_author->author_id );
4411:
4412: $second_agent = get_property_meta( 'property_second_agent' );
4413: $third_agent = get_property_meta( 'property_third_agent' );
4414: $fourth_agent = get_property_meta( 'property_fourth_agent' );
4415:
4416: $second_author_id = epl_get_agent_id_by_login( $second_agent );
4417: $third_author_id = epl_get_agent_id_by_login( $third_agent );
4418: $fourth_author_id = epl_get_agent_id_by_login( $fourth_agent );
4419:
4420: if ( false !== $second_author_id ) {
4421: $agents[] = $second_author_id;
4422: }
4423: if ( false !== $third_author_id ) {
4424: $agents[] = $third_author_id;
4425: }
4426: if ( false !== $fourth_author_id ) {
4427: $agents[] = $fourth_author_id;
4428: }
4429:
4430: $agents = array_unique( $agents );
4431: $count = count( $agents );
4432:
4433: return apply_filters( 'epl_get_active_agent_count', $count );
4434: }
4435:
4436: /**
4437: * Wrapper Start for Author Box
4438: *
4439: * @since 3.5.1
4440: * @since 3.5.3 Added counter class for number of agents.
4441: */
4442: function epl_single_author_wrapper_start() {
4443:
4444: $counter = epl_get_total_agent_count();
4445: $active = epl_get_active_agent_count();
4446: ?>
4447: <div class="epl-author-box-wrapper epl-author-box-wrapper--count-<?php echo esc_attr( $active ); ?> epl-author-box-wrapper--total-<?php echo esc_attr( $counter ); ?> ">
4448: <?php
4449: }
4450: add_action( 'epl_single_author', 'epl_single_author_wrapper_start', 1 );
4451:
4452: /**
4453: * Wrapper end for Author Box
4454: *
4455: * @since 3.5.1
4456: */
4457: function epl_single_author_wrapper_end() {
4458: ?>
4459: </div>
4460: <?php
4461: }
4462: add_action( 'epl_single_author', 'epl_single_author_wrapper_end', 99 );
4463:
4464: /**
4465: * Check if the value is truthy / falsy.
4466: *
4467: * @param string $value Values.
4468: *
4469: * @return bool
4470: *
4471: * @since 3.5.13
4472: */
4473: function epl_value_bool_checker( $value ) {
4474:
4475: $truthy_values = array( 1, 'yes', 'true' );
4476: $truthy_values = apply_filters( 'epl_truthy_values', $truthy_values );
4477:
4478: if ( in_array( $value, $truthy_values, true ) ) {
4479: return true;
4480: } else {
4481: return false;
4482: }
4483: }
4484: