1: <?php
2: /**
3: * EPL Functions Compatibility
4: *
5: * @package EPL
6: * @subpackage Compatibility/Functions
7: * @copyright Copyright (c) 2014, 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: /**
18: * Get EPL author meta.
19: *
20: * @return void list of author meta variables
21: * @since 1.0
22: */
23: function epl_get_author_meta() {
24: global $epl_author_meta_sent;
25: if ( $epl_author_meta_sent ) {
26: return;
27: }
28:
29: require_once EPL_PATH_LIB . 'templates/content/author-meta.php';
30: $epl_author_meta_sent = true;
31: }
32:
33: /**
34: * Print EPL property address.
35: *
36: * @param string $post_ID post id.
37: *
38: * @return void
39: * @since 1.0
40: */
41: function epl_the_property_address( $post_ID = '' ) {
42: $address = epl_get_property_address( $post_ID );
43: $address = apply_filters( 'epl_the_property_address_filter', $address );
44: echo esc_attr( $address );
45: }
46:
47: /**
48: * Get EPL property address.
49: *
50: * @param string $post_ID post id.
51: *
52: * @return string The address
53: * @since 1.0
54: * @since 3.6 Fix: the street number and street are left out when the listing hides its street address, and the suburb follows the listing's show_suburb() rule, as in epl_get_the_address().
55: */
56: function epl_get_property_address( $post_ID = '' ) {
57: if ( empty( $post_ID ) ) {
58: $post_ID = get_the_ID();
59: }
60: $property_meta = (array) epl_get_property_meta( $post_ID );
61: $post = get_post( $post_ID );
62: $hidden = array();
63:
64: if ( $post ) {
65: $listing = new EPL_Property_Meta( $post );
66:
67: if ( ! $listing->show_street_address() ) {
68: $hidden[] = 'property_address_street_number';
69: $hidden[] = 'property_address_street';
70: }
71:
72: if ( ! $listing->show_suburb() ) {
73: $hidden[] = 'property_address_suburb';
74: }
75: }
76:
77: $property_meta = array_diff_key( $property_meta, array_flip( $hidden ) );
78:
79: $address = '';
80:
81: if ( isset( $property_meta['property_address_street_number'] ) && ! empty( $property_meta['property_address_street_number'] ) ) {
82: $property_address_street_number = $property_meta['property_address_street_number'][0];
83: if ( ! empty( $property_address_street_number ) ) {
84: $address .= $property_address_street_number . ', ';
85: }
86: }
87:
88: if ( isset( $property_meta['property_address_street'] ) && ! empty( $property_meta['property_address_street'] ) ) {
89: $property_address_street = $property_meta['property_address_street'][0];
90: if ( ! empty( $property_address_street ) ) {
91: $address .= $property_address_street . ', ';
92: }
93: }
94:
95: if ( isset( $property_meta['property_address_suburb'] ) && ! empty( $property_meta['property_address_suburb'] ) ) {
96: $property_address_suburb = $property_meta['property_address_suburb'][0];
97: if ( ! empty( $property_address_suburb ) ) {
98: $address .= $property_address_suburb . ', ';
99: }
100: }
101:
102: if ( isset( $property_meta['property_address_state'] ) && ! empty( $property_meta['property_address_state'] ) ) {
103: $property_address_state = $property_meta['property_address_state'][0];
104: if ( ! empty( $property_address_state ) ) {
105: $address .= $property_address_state . ', ';
106: }
107: }
108:
109: if ( isset( $property_meta['property_address_postal_code'] ) && ! empty( $property_meta['property_address_postal_code'] ) ) {
110: $property_address_postal_code = $property_meta['property_address_postal_code'][0];
111: if ( ! empty( $property_address_postal_code ) ) {
112: $address .= $property_address_postal_code . ', ';
113: }
114: }
115:
116: $address = trim( $address );
117: $address = trim( $address, ',' );
118: $address = trim( $address );
119: return apply_filters( 'epl_get_property_address_filter', $address );
120: }
121:
122: /**
123: * Get postcode label. Depreciated use epl_labels instead.
124: *
125: * @since 1.0
126: * @depricated since 2.2. use epl_labels instead.
127: */
128: function epl_display_label_postcode() {
129: $epl_display_label_postcode = '';
130:
131: global $epl_settings;
132: if ( ! empty( $epl_settings ) && isset( $epl_settings['label_postcode'] ) ) {
133: $epl_display_label_postcode = $epl_settings['label_postcode'];
134: }
135: return apply_filters( 'epl_display_label_postcode', $epl_display_label_postcode );
136: }
137:
138: /**
139: * Get bond label. Depreciated use epl_labels instead.
140: *
141: * @since 1.0
142: * @depricated since 2.2. use epl_labels instead.
143: */
144: function epl_display_label_bond() {
145: $epl_display_label_bond = '';
146:
147: global $epl_settings;
148: if ( ! empty( $epl_settings ) && isset( $epl_settings['label_bond'] ) ) {
149: $epl_display_label_bond = $epl_settings['label_bond'];
150: }
151: return apply_filters( 'epl_display_label_bond', $epl_display_label_bond );
152: }
153:
154: /**
155: * Get suburb label. Depreciated use epl_labels instead.
156: *
157: * @since 1.0
158: * @depricated since 2.2. use epl_labels instead.
159: */
160: function epl_display_label_suburb() {
161: $epl_display_label_suburb = '';
162:
163: global $epl_settings;
164: if ( ! empty( $epl_settings ) && isset( $epl_settings['label_suburb'] ) ) {
165: $epl_display_label_suburb = $epl_settings['label_suburb'];
166: }
167: return apply_filters( 'epl_display_label_suburb', $epl_display_label_suburb );
168: }
169:
170: // Front End Functions.
171: if ( ! is_admin() ) {
172: return;
173: }
174:
175: /**
176: * Listing Function for paged card display.
177: *
178: * @compat not being used @since 1.3 in core, but still kept for extensions which may be using this function
179: * @since 1.3
180: */
181: function epl_property_blog_default() {
182:
183: global $property, $epl_settings;
184: $property_status = $property->get_property_meta( 'property_status' );
185:
186: // Status Removal Do Not Display Withdrawn or OffMarket listings.
187: if ( ! in_array( $property_status, array( 'withdrawn', 'offmarket' ), true ) ) {
188: // Do Not Display Withdrawn or OffMarket listings.
189: $option = '';
190: if ( ! empty( $epl_settings ) && isset( $epl_settings['epl_property_card_style'] ) ) {
191: $option = $epl_settings['epl_property_card_style'];
192: }
193:
194: $action_check = has_action( 'epl_loop_template' );
195: if ( ! empty( $action_check ) && 0 !== $option ) {
196: do_action( 'epl_loop_template' );
197: } else {
198: epl_get_template_part( 'loop-listing-blog-default.php' );
199: }
200: }
201: }
202:
203: /**
204: * Listing Function for slim view.
205: *
206: * @compat not being used @since 1.3 in core, but still kept for extensions which may be using this function
207: * @since 1.3
208: */
209: function epl_property_blog_slim() {
210: global $property, $epl_settings;
211: if ( is_null( $property ) ) {
212: return;
213: }
214: $property_status = $property->get_property_meta( 'property_status' );
215: // Status Removal.
216: if ( ! in_array( $property_status, array( 'withdrawn', 'offmarket' ), true ) ) {
217: // Do Not Display Withdrawn or OffMarket listings.
218: $option = '';
219: if ( ! empty( $epl_settings ) && isset( $epl_settings['epl_property_card_style'] ) ) {
220: $option = $epl_settings['epl_property_card_style'];
221: }
222:
223: $action_check = has_action( 'epl_loop_template' );
224: if ( ! empty( $action_check ) && 0 !== $option ) {
225: do_action( 'epl_loop_template' );
226: } else {
227: epl_get_template_part( 'loop-listing-blog-slim.php' );
228: }
229: }
230: }
231:
232: /**
233: * Listing Function for table open.
234: *
235: * @since 2.1.6
236: */
237: function epl_property_blog_table() {
238: global $property, $epl_settings;
239: if ( is_null( $property ) ) {
240: return;
241: }
242: $property_status = $property->get_property_meta( 'property_status' );
243: // Status Removal.
244: if ( ! in_array( $property_status, array( 'withdrawn', 'offmarket' ), true ) ) {
245: // Do Not Display Withdrawn or OffMarket listings.
246: $option = '';
247: if ( ! empty( $epl_settings ) && isset( $epl_settings['epl_property_card_style'] ) ) {
248: $option = $epl_settings['epl_property_card_style'];
249: }
250:
251: $action_check = has_action( 'epl_loop_template' );
252: if ( ! empty( $action_check ) && 0 !== $option ) {
253: do_action( 'epl_loop_template' );
254: } else {
255: epl_get_template_part( 'loop-listing-blog-table.php' );
256: }
257: }
258: }
259:
260: /**
261: * Listing Function for table open.
262: *
263: * Kept for extensions which may be using this function.
264: *
265: * @since 2.1.8
266: */
267: function epl_property_blog_table_open() {
268: global $property, $epl_settings;
269: if ( is_null( $property ) ) {
270: return;
271: }
272: $property_status = $property->get_property_meta( 'property_status' );
273: // Status Removal.
274: if ( ! in_array( $property_status, array( 'withdrawn', 'offmarket' ), true ) ) {
275: // Do Not Display Withdrawn or OffMarket listings.
276: $option = '';
277: if ( ! empty( $epl_settings ) && isset( $epl_settings['epl_property_card_style'] ) ) {
278: $option = $epl_settings['epl_property_card_style'];
279: }
280:
281: $action_check = has_action( 'epl_loop_template' );
282: if ( ! empty( $action_check ) && 0 !== $option ) {
283: do_action( 'epl_loop_template' );
284: } else {
285: epl_get_template_part( 'loop-listing-blog-table-open.php' );
286: }
287: }
288: }
289:
290: /**
291: * TEMPLATE - Leased/sold property list.
292: *
293: * Kept for extensions which may be using this function.
294: *
295: * @since 1.3
296: */
297: function epl_property_sold_leased() {
298: $property_suburb = get_post_custom_values( 'property_address_suburb' );
299: $post_id = $property_suburb[0]['ID'];
300: $post = get_post( $post_id );
301: $terms = get_the_terms( $post->ID, 'location' );
302: if ( ! empty( $terms ) ) {
303: global $post;
304: foreach ( $terms as $term ) {
305: $term->slug;
306: }
307: }
308:
309: $post_type = get_post_type();
310:
311: if ( 'property' === $post_type ) {
312: $query = new WP_Query(
313: array(
314: 'post_type' => 'property',
315: 'location' => $term->slug,
316: 'meta_query' => array(
317: array(
318: 'key' => 'property_status',
319: 'value' => 'sold',
320: ),
321: ),
322: 'posts_per_page' => '5',
323: )
324: );
325: } elseif ( 'land' === $post_type ) {
326: $query = new WP_Query(
327: array(
328: 'post_type' => 'land',
329: 'meta_query' => array(
330: array(
331: 'key' => 'property_status',
332: 'value' => 'sold',
333: ),
334: ),
335: 'property_status' => 'sold',
336: 'posts_per_page' => '5',
337: )
338: );
339: } elseif ( 'rural' === $post_type ) {
340: $query = new WP_Query(
341: array(
342: 'post_type' => 'rural',
343: 'location' => $term->slug,
344: 'meta_query' => array(
345: array(
346: 'key' => 'property_status',
347: 'value' => 'sold',
348: ),
349: ),
350: 'posts_per_page' => '5',
351: )
352: );
353: } else {
354: $query = new WP_Query(
355: array(
356: 'post_type' => 'rental',
357: 'location' => $term->slug,
358: 'meta_query' => array(
359: array(
360: 'key' => 'property_status',
361: 'value' => 'leased',
362: ),
363: ),
364: 'posts_per_page' => '5',
365: )
366: );
367: }
368:
369: if ( $query->have_posts() ) { ?>
370: <div class="epl-tab-section epl-tab-section-listing-history">
371: <?php if ( 'property' === $post_type || 'land' === $post_type || 'rural' === $post_type ) { ?>
372: <h5 class="epl-tab-title epl-tab-title-sales tab-title"><?php esc_html_e( 'Recently Sold', 'easy-property-listings' ); ?></h5>
373: <?php } else { ?>
374: <h5 class="epl-tab-title epl-tab-title-leased tab-title"><?php esc_html_e( 'Recently Leased', 'easy-property-listings' ); ?></h5>
375: <?php } ?>
376: <div class="tab-content">
377: <ul>
378: <?php
379: while ( $query->have_posts() ) {
380: $query->the_post();
381: ?>
382:
383: <!-- Suburb Tab -->
384: <li>
385: <a href="<?php the_permalink(); ?>">
386: <?php the_title(); ?>
387: <?php echo esc_attr( $suburb[0] ); ?>
388: </a>
389: </li>
390: <?php
391: }
392: ?>
393: </ul>
394: </div>
395: </div>
396: <?php
397: }
398: wp_reset_postdata();
399: }
400:
401: /**
402: * Staff Directory Card.
403: *
404: * Kept for extensions which may be using this function.
405: *
406: * @since 1.3
407: * @param string $display post id.
408: * @param string $image on off switch.
409: * @param string $title on off switch.
410: * @param string $icons styling switch.
411: */
412: function epl_property_author_card( $display, $image, $title, $icons ) {
413: global $property, $epl_author;
414: if ( is_null( $epl_author ) ) {
415: return;
416: }
417: $property_status = $property->get_property_meta( 'property_status' );
418: // Status Removal.
419: if ( ! in_array( $property_status, array( 'withdrawn', 'offmarket' ), true ) ) {
420:
421: // Do Not Display Withdrawn or OffMarket listings.
422: ?>
423: <div id="post-<?php the_ID(); ?>" style="width: 20%;margin-right: 1em;float: left;" class="epl-widget property-widget-image hentry">
424: <div class="entry-header">
425: <?php if ( has_post_thumbnail() ) : ?>
426: <div class="epl-img-widget">
427: <a href="<?php the_permalink(); ?>">
428: <?php the_post_thumbnail( $image ); ?>
429: </a>
430: </div>
431: <?php endif; ?>
432: </div>
433:
434: <div class="entry-content">
435: <?php
436: // Heading Options.
437: if ( 'on' === $title ) {
438: ?>
439: <h5 class="property-meta heading"><?php echo wp_kses( $the_property_heading ); ?></h5>
440: <?php
441: }
442: ?>
443:
444: <!-- Address -->
445: <div class="property-address">
446: <?php do_action( 'epl_property_address' ); ?>
447: </div>
448: <!-- END Address -->
449:
450: <?php
451: // Icon Options.
452: if ( 'all' === $icons ) {
453: ?>
454: <div class="property-meta property-feature-icons"><?php epl_property_icons(); ?></div>
455: <?php } elseif ( 'bb' === $icons ) { ?>
456: <div class="property-meta property-feature-icons"><?php echo wp_kses( epl_get_property_bb_icons(), array_merge( wp_kses_allowed_html( 'post' ), epl_get_svg_allowed_tags() ) ); ?></div>
457: <?php } ?>
458:
459: <div class="property-meta price"><?php epl_property_price(); ?></div>
460: <form class="epl-property-button" action="<?php the_permalink(); ?>" method="post">
461: <input type=submit value="<?php esc_html_e( 'Read More', 'easy-property-listings' ); ?>" />
462: </form>
463: </div>
464: </div>
465:
466: <?php
467: }
468: }
469:
470: /**
471: * Modify the Excerpt length on archive pages
472: *
473: * @param int $length Excerpt word length.
474: *
475: * @return int
476: * @since 1.0.0
477: * @since 3.4.27 Depreciated function and deactivated filter.
478: */
479: function epl_excerpt_length( $length ) {
480: global $post;
481: if ( 'property' === $post->post_type ) {
482: return 16;
483: } elseif ( 'rental' === $post->post_type ) {
484: return 16;
485: } elseif ( 'commercial' === $post->post_type ) {
486: return 16;
487: } elseif ( 'commercial_land' === $post->post_type ) {
488: return 16;
489: } elseif ( 'business' === $post->post_type ) {
490: return 16;
491: } elseif ( 'rural' === $post->post_type ) {
492: return 16;
493: } elseif ( 'land' === $post->post_type ) {
494: return 16;
495: } elseif ( 'suburb' === $post->post_type ) {
496: return 39;
497: } else {
498: return 55;
499: }
500: }
501: /**
502: * Filter Removed. add_filter( 'excerpt_length', 'epl_excerpt_length', 999 ); Removed due to fix.
503: */
504: