| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | if ( ! defined( 'ABSPATH' ) ) { |
| 14: | exit; |
| 15: | } |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | class EPL_Listing_Elements { |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | public function __construct() { |
| 30: | add_shortcode( 'listing_element', array( $this, 'listing_element' ) ); |
| 31: | add_shortcode( 'epl_listing_action', array( $this, 'epl_action' ) ); |
| 32: | add_shortcode( 'epl_listing_meta', array( $this, 'epl_meta' ) ); |
| 33: | add_shortcode( 'epl_listing_post', array( $this, 'post' ) ); |
| 34: | add_action( 'epl_suburb_profile', array( $this, 'epl_suburb_profile' ) ); |
| 35: | add_action( 'epl_listing_address', array( $this, 'epl_formatted_address' ) ); |
| 36: | add_shortcode( 'epl_listing_excerpt', array( $this, 'epl_the_excerpt' ) ); |
| 37: | } |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | public function listing_element( $atts ) { |
| 48: | |
| 49: | global $property; |
| 50: | |
| 51: | if ( ! isset( $atts['type'] ) ) { |
| 52: | return; |
| 53: | } |
| 54: | |
| 55: | if ( is_null( $property ) ) { |
| 56: | |
| 57: | $key_name = ''; |
| 58: | |
| 59: | switch ( $atts['type'] ) { |
| 60: | |
| 61: | case 'action': |
| 62: | $key_name = 'action_key'; |
| 63: | break; |
| 64: | |
| 65: | case 'meta': |
| 66: | $key_name = 'meta_key'; |
| 67: | break; |
| 68: | |
| 69: | case 'post': |
| 70: | $key_name = 'post_key'; |
| 71: | break; |
| 72: | |
| 73: | } |
| 74: | |
| 75: | ob_start(); |
| 76: | echo '[ ' . esc_html__( 'Listing', 'easy-property-listings' ) . ' ' . esc_attr( ucwords( $atts['type'] ) ); |
| 77: | |
| 78: | if ( ! empty( $key_name ) ) { |
| 79: | echo ': ' . esc_attr( ucwords( str_replace( '_', ' ', $atts[ $key_name ] ) ) ); |
| 80: | } |
| 81: | echo ' ]'; |
| 82: | |
| 83: | return ob_get_clean(); |
| 84: | } |
| 85: | |
| 86: | $return = ''; |
| 87: | |
| 88: | switch ( $atts['type'] ) { |
| 89: | |
| 90: | case 'action': |
| 91: | $return = $this->epl_action( $atts ); |
| 92: | break; |
| 93: | |
| 94: | case 'meta': |
| 95: | $return = $this->epl_meta( $atts ); |
| 96: | break; |
| 97: | |
| 98: | case 'post': |
| 99: | $return = $this->post( $atts ); |
| 100: | break; |
| 101: | |
| 102: | case 'suburb_profile': |
| 103: | $return = $this->epl_suburb_profile(); |
| 104: | break; |
| 105: | |
| 106: | case 'formatted_address': |
| 107: | $return = $this->epl_formatted_address(); |
| 108: | break; |
| 109: | |
| 110: | case 'excerpt': |
| 111: | $return = $this->epl_the_excerpt(); |
| 112: | break; |
| 113: | |
| 114: | } |
| 115: | |
| 116: | return $return; |
| 117: | } |
| 118: | |
| 119: | |
| 120: | |
| 121: | |
| 122: | |
| 123: | |
| 124: | |
| 125: | |
| 126: | |
| 127: | public function epl_action( $atts ) { |
| 128: | if ( ! isset( $atts['action_key'] ) ) { |
| 129: | return; |
| 130: | } |
| 131: | ob_start(); |
| 132: | do_action( $atts['action_key'] ); |
| 133: | return ob_get_clean(); |
| 134: | } |
| 135: | |
| 136: | |
| 137: | |
| 138: | |
| 139: | |
| 140: | |
| 141: | |
| 142: | |
| 143: | |
| 144: | public function epl_meta( $atts ) { |
| 145: | |
| 146: | if ( ! isset( $atts['meta_key'] ) ) { |
| 147: | return; |
| 148: | } |
| 149: | |
| 150: | return get_property_meta( $atts['meta_key'] ); |
| 151: | } |
| 152: | |
| 153: | |
| 154: | |
| 155: | |
| 156: | |
| 157: | |
| 158: | |
| 159: | |
| 160: | |
| 161: | public function post( $atts ) { |
| 162: | |
| 163: | global $property; |
| 164: | |
| 165: | $return = ''; |
| 166: | switch ( $atts['post_key'] ) { |
| 167: | |
| 168: | case 'permalink': |
| 169: | $return = get_permalink( $property->post->ID ); |
| 170: | break; |
| 171: | |
| 172: | default: |
| 173: | $return = isset( $property->post->{$atts['post_key']} ) ? $property->post->{$atts['post_key']} : ''; |
| 174: | break; |
| 175: | |
| 176: | } |
| 177: | |
| 178: | return $return; |
| 179: | } |
| 180: | |
| 181: | |
| 182: | |
| 183: | |
| 184: | |
| 185: | |
| 186: | public function epl_suburb_profile() { |
| 187: | |
| 188: | global $property; |
| 189: | echo esc_html( $property->get_suburb_profile() ); |
| 190: | } |
| 191: | |
| 192: | |
| 193: | |
| 194: | |
| 195: | |
| 196: | |
| 197: | public function epl_formatted_address() { |
| 198: | |
| 199: | global $property; |
| 200: | echo esc_html( $property->get_formatted_property_address() ); |
| 201: | } |
| 202: | |
| 203: | |
| 204: | |
| 205: | |
| 206: | |
| 207: | |
| 208: | public function epl_the_excerpt() { |
| 209: | |
| 210: | global $property; |
| 211: | return esc_html( epl_get_the_excerpt() ); |
| 212: | } |
| 213: | } |
| 214: | |
| 215: | new EPL_Listing_Elements(); |
| 216: | |