· 6 years ago · Jul 23, 2019, 01:26 PM
1<?php
2/*
3 Plugin Name: PS - Core
4 Plugin URI: http://www.propertystream.co/
5 Description: Bootstrap plugin to setup the post types and taxonomies
6 Author: PropertyStream
7 Author URI: http://www.propertystream.co/
8 Copyright: 2016 Property Stream
9 Text Domain: propertystreambootstrap
10 Domain Path: /lang
11 Version: 1.1.4
12 */
13
14/** Plugin security */
15if ( !defined('ABSPATH') ) {
16 die();
17}
18
19
20/** Plugin define constants */
21define('PSBOOTSTRAP_PLUGIN_FILE', __FILE__);
22define('PSBOOTSTRAP_PLUGIN_URL', plugin_dir_url(__FILE__));
23define('PSBOOTSTRAP_PLUGIN_PATH', plugin_dir_path(__FILE__));
24define('PSBOOTSTRAP_AJAX_KEY', 'x8sd8cn23xc098xcn7');
25
26/** File includes */
27require_once PSBOOTSTRAP_PLUGIN_PATH . "geolocation.php";
28
29/** Action hooks **/
30register_activation_hook(PSBOOTSTRAP_PLUGIN_FILE, ['Ps_Bootstrap', 'activation']);
31add_action('init', ['Ps_Bootstrap', 'init']);
32add_action('add_meta_boxes', ['Ps_Bootstrap', 'add_meta_boxes']);
33add_action('before_delete_post', ['Ps_Bootstrap', 'clean_unused_images']);
34add_action('manage_property_posts_custom_column', ['Ps_Bootstrap', 'custom_columns'], 10, 2);
35add_action('wp_ajax_update_meta', ['Ps_Bootstrap', 'ajax_postmeta_function']);
36add_action('admin_enqueue_scripts', ['Ps_Bootstrap', 'admin_enqueue_scripts']);
37add_action('admin_menu', ['Ps_Bootstrap', 'admin_menu']);
38//add_action('save_post', ['Ps_Bootstrap', 'save_post'], 10, 3);
39add_action('acf/input/admin_head', ['Ps_Bootstrap', 'admin_head']);
40add_filter('acf/settings/load_json', ['Ps_Bootstrap', 'load_json']);
41add_filter('manage_edit-property_columns', ['Ps_Bootstrap', 'heading_columns']);
42add_filter('manage_edit-property_sortable_columns', ['Ps_Bootstrap', 'sortable_columns']);
43
44/**
45 *
46 *
47 */
48class Ps_Bootstrap
49{
50
51 /**
52 * Method called on plugin activation
53 * @access public
54 * @static
55 * @final
56 */
57 final public static function activation ()
58 {
59 self::create_coords_table();
60 }
61
62 /**
63 * Create the coordinates table to register against properties
64 * @access private
65 * @static
66 * @final
67 */
68 final private static function create_coords_table ()
69 {
70 global $wpdb;
71 $sql = "CREATE TABLE IF NOT EXISTS ".$wpdb->prefix."post_coordinates (
72 id INT( 11 ) NOT NULL AUTO_INCREMENT,
73 lat VARCHAR( 10 ) NOT NULL,
74 lng VARCHAR( 10 ) NULL,
75 post_id BIGINT( 20 ) UNSIGNED NOT NULL,
76 PRIMARY KEY (id),
77 FOREIGN KEY (post_id) REFERENCES ".$wpdb->prefix."posts (ID)
78 ON DELETE CASCADE
79 ON UPDATE CASCADE
80 );";
81 $ret = $wpdb->query($sql);
82
83 return null;
84 }
85
86 /**
87 * Method called on plugin admin_menu
88 * @access public
89 * @static
90 * @final
91 */
92 final public static function admin_menu ()
93 {
94 self::remove_property_menu_item();
95 }
96
97 /**
98 * Method called on WordPress init
99 * @access public
100 * @static
101 * @final
102 */
103 final public static function init ()
104 {
105 self::register_post_types();
106 self::register_taxonomies();
107 self::url_rewrite();
108 }
109
110 /**
111 * Method called on plugin save_post
112 * @access public
113 * @static
114 * @final
115 */
116 final public static function save_post ($post_id, $post, $update)
117 {
118 self::attach_gallery_images($post_id, $post, $update);
119 //remove_action('save_post', ['Ps_Bootstrap', 'save_post']);
120 // self::add_content_to_thumnail($post_id, $post, $update);
121 }
122
123 /**
124 * acf/settings/load_json hook
125 *
126 * @access public
127 * @final
128 * @static
129 * @return null
130 */
131 final public static function load_json ($paths)
132 {
133 return self::acf_json_load_point($paths);
134 }
135
136 /**
137 * admin_head hook
138 *
139 * @final
140 * @access public
141 * @static
142 * @return null
143 */
144 final public static function admin_head()
145 {
146 self::acf_admin_head();
147 return null;
148}
149
150 /**
151 * Remove the property menu item
152 * @access public
153 * @static
154 * @final
155 */
156 final public static function remove_property_menu_item ()
157 {
158 if( !current_user_can( 'administrator' ) ):
159 remove_menu_page( 'edit.php?post_type=property' );
160 endif;
161 }
162
163 /**
164 * Register our plugin post types
165 * @access public
166 * @static
167 * @final
168 */
169 final private static function register_post_types ()
170 {
171 $labels = array(
172 'name' => _x( 'Properties', 'post type general name', ' propertystreambootstrap' ),
173 'singular_name' => _x( 'Property', 'post type singular name', ' propertystreambootstrap' ),
174 'menu_name' => _x( 'Properties', 'admin menu', ' propertystreambootstrap' ),
175 'name_admin_bar' => _x( 'Property', 'add new on admin bar', ' propertystreambootstrap' ),
176 'add_new' => _x( 'Add New', 'property', ' propertystreambootstrap' ),
177 'add_new_item' => __( 'Add New Property', ' propertystreambootstrap' ),
178 'new_item' => __( 'New Property', ' propertystreambootstrap' ),
179 'edit_item' => __( 'Edit Property', ' propertystreambootstrap' ),
180 'view_item' => __( 'View Property', ' propertystreambootstrap' ),
181 'all_items' => __( 'All Properties', ' propertystreambootstrap' ),
182 'search_items' => __( 'Search Properties', ' propertystreambootstrap' ),
183 'parent_item_colon' => __( 'Parent Properties:', ' propertystreambootstrap' ),
184 'not_found' => __( 'No properties found.', ' propertystreambootstrap' ),
185 'not_found_in_trash' => __( 'No properties found in Trash.', ' propertystreambootstrap' )
186 );
187
188 $args = array(
189 'labels' => $labels,
190 'description' => __( 'Properties for your website.', ' propertystreambootstrap' ),
191 'public' => true,
192 'publicly_queryable' => true,
193 'show_ui' => true,
194 'show_in_menu' => true,
195 'menu_icon' => 'dashicons-building',
196 'query_var' => true,
197 'rewrite' => array( 'slug' => 'malta-property/%trans_type%/%location%/%reference%' ),
198 //'rewrite' => array( 'slug' => 'malta-property'),
199 'has_archive' => 'about-cool-post-types',
200 'capability_type' => 'post',
201 'has_archive' => false,
202 'hierarchical' => false,
203 'menu_position' => null,
204 'supports' => array('title', 'editor', 'excerpt', 'post-thumbnails', 'thumbnail')
205 );
206 register_post_type( 'property', $args );
207
208 }
209
210 final public static function url_rewrite()
211 {
212 global $wp_rewrite;
213 $permastruct = $wp_rewrite->extra_permastructs['property'];
214 $permastruct['struct'] = str_replace( '/%property%', '', $permastruct['struct'] );
215 $wp_rewrite->extra_permastructs['property'] = $permastruct;
216 $wp_rewrite->add_rewrite_tag('%reference%', '([^/]+)', 'reference=');
217 $wp_rewrite->add_rewrite_tag('%trans_type%', '([^/]*)', 'trans_type=');
218 $wp_rewrite->add_rewrite_tag('%location%', '([^/]*)', 'location=');
219 return null;
220 }
221
222 /**
223 * Our list of columns that we are sorting by for our custom post type
224 * @access public
225 * @static
226 * @final
227 */
228 final public static function heading_columns ($defaults)
229 {
230 $new_default['cb'] = $defaults['cb'];
231 $new_default['title'] = $defaults['title'];
232 $new_default['display_address'] = 'Address';
233 $defaults = array_merge($new_default, $defaults);
234 return $defaults;
235 }
236
237 /**
238 * Our list of columns that we are sorting by for our custom post type
239 * @access public
240 * @static
241 * @final
242 */
243 final public static function custom_columns ($column_name, $post_ID)
244 {
245 if ($column_name == 'display_address') {
246 $address = self::get_display_address($post_ID);
247 if ($address) {
248 echo $address;
249 }
250 }
251 }
252
253 /**
254 * Our list of columns that we are sorting by for our custom post type
255 * @access public
256 * @static
257 * @final
258 */
259 final private static function get_display_address ($post_ID)
260 {
261 $address = get_post_meta($post_ID, 'propertystream_display_address', true);
262 if ($address) {
263 return $address;
264 }
265 return null;
266 }
267
268 /**
269 * Our list of columns that we are sorting by for our custom post type
270 * @var array $columns The columns in the sortable list from WP
271 * @access public
272 * @static
273 * @final
274 */
275 final public static function sortable_columns ($columns)
276 {
277 $columns['display_address'] = 'Address';
278 return $columns;
279 }
280
281 /**
282 * Register our plugin meta boxes
283 * @access public
284 * @static
285 * @final
286 */
287 final public static function add_meta_boxes ()
288 {
289 if(isset($_GET['post'])) {
290 //add_meta_box('ps_bootstrap_property_attachments', 'Media Files', ['Ps_Bootstrap', 'add_meta_boxes_attachments'], 'property', 'normal', 'default');
291 // add_meta_box('ps_bootstrap_property_coordinates', 'Location', ['Ps_Bootstrap', 'add_meta_boxes_coordinates'], 'property', 'normal', 'default');
292 // add_meta_box('ps_bootstrap_property_additionals', 'Additional Settings', ['Ps_Bootstrap', 'add_meta_boxes_additionals'], 'property', 'normal', 'default');
293 }
294 }
295
296 /**
297 * Register our plugin media attachments meta box
298 * @access public
299 * @static
300 * @final
301 */
302 final public static function add_meta_boxes_attachments ()
303 {
304 echo '<button type="button" id="insert-media-button" class="button insert-media add_media" data-editor="content"><span class="wp-media-buttons-icon"></span> Add Media</button>';
305 echo '<hr/>';
306 $args = array(
307 'post_parent' => $_GET['post'],
308 'post_type' => 'any',
309 'numberposts' => -1,
310 'post_status' => 'any'
311 );
312 $children_array = get_children( $args);
313 $images = '';
314 $others = '';
315 foreach ( $children_array as $attachment ) {
316 $srcUrl = wp_get_attachment_url( $attachment->ID );
317 $filetype = wp_check_filetype($srcUrl);
318 if(in_array($filetype['ext'], ['gif', 'jpg', 'png'])) {
319 $images .= '<img src="' . $srcUrl . '" style="width:100px; margin:5px; display: inline-block; border:1px solid #555;"" />';
320 } else {
321 $others .= '<p><a href="'.$srcUrl.'" target="_blank" />'.$srcUrl.'</a></p>';
322 }
323 }
324 if(!empty($images)) {
325 echo '<h3>Images</h3>' . $images;
326 }
327 if(!empty($others)) {
328 echo '<h3>Other files</h3>' . $others;
329 }
330 }
331
332 /**
333 * Register our plugin coordinates meta box
334 * @access public
335 * @static
336 * @final
337 */
338 final public static function add_meta_boxes_coordinates ()
339 {
340 echo '<h3>Property Location</h3>';
341 echo '<p>We are geolocating this property based on the following details below. Change these details to update the geolocation.</p>';
342 echo '<form method="post" class="ps-coordinates-update">';
343 wp_nonce_field('propertystream-geolocate-action', 'propertystream-geolocate-field');
344 echo '<p><input type="text" name="propertystream_address_1" data-post="'.$_GET['post'].'" class="ps-ajax-meta" value="' . get_post_meta($_GET['post'], 'propertystream_address_1', true) . '" />';
345 echo '<br/><input type="text" name="propertystream_address_2" data-post="'.$_GET['post'].'" class="ps-ajax-meta" value="' . get_post_meta($_GET['post'], 'propertystream_address_2', true) . '" />';
346 echo '<br/><input type="text" name="propertystream_postcode1" data-post="'.$_GET['post'].'" class="ps-ajax-meta" value="' . get_post_meta($_GET['post'], 'propertystream_postcode1', true) . '" />'.
347 '<input type="text" name="propertystream_postcode2" data-post="'.$_GET['post'].'" class="ps-ajax-meta" value="' . get_post_meta($_GET['post'], 'propertystream_postcode2', true) . '" /></p>';
348 echo '<p><input type="submit" value="Click Here To Update Coordinates" class="button button-default" /></p>';
349 echo '</form>';
350
351 global $wpdb;
352 $sql = "SELECT * FROM {$wpdb->prefix}post_coordinates WHERE post_id = {$_GET['post']}";
353 $row = $wpdb->get_row($sql);
354 if(!empty($row)) {
355 ?>
356 <div id="map" style="height:300px; border:1px solid #ddd;" data-lat="<?php echo $row->lat ;?>" data-lng="<?php echo $row->lng ;?>"></div>
357 <?php
358 } else {
359 echo '<p>No location coordinates have been saved for this property</p>';
360 }
361 }
362
363 /**
364 * Register our plugin media attachments meta box
365 * @access public
366 * @static
367 * @final
368 */
369 final public static function add_meta_boxes_additionals ()
370 {
371 echo 'Additional Post Meta stuff';
372 $meta = get_post_meta ($_GET['post'], null, true);
373 $use_meta = ['propertystream_bedrooms', 'propertystream_price', ];
374 foreach($meta as $key => $val) {
375 if(strpos($key, 'propertystream') !== false) {
376 if(in_array($key, $use_meta)) {
377 echo $key . '<br/>';
378 echo utf8_decode($val[0]);
379 echo '<hr/><hr/>';
380 }
381 }
382 }
383 }
384
385 /**
386 * Register our plugin taxonomies
387 * @access private
388 * @static
389 * @final
390 */
391 final private static function register_taxonomies ()
392 {
393 foreach(self::$taxonomies as $taxonomy) {
394 register_taxonomy(
395 $taxonomy['name'],
396 'property',
397 ['label' => __( $taxonomy['label'] ), 'public' => true, 'rewrite' => true, 'hierarchical' => true,] );
398 foreach($taxonomy['terms'] as $key => $term) {
399 $term_exists = term_exists($term['label'], $taxonomy['name']);
400 if ($term_exists === 0 || $term_exists === null) {
401 if(!empty($term['label'])) {
402 $new_term = wp_insert_term(
403 $term['label'] . 'test', // the term
404 $taxonomy['name'], // the taxonomy
405 ['description'=> ucfirst(strtolower($term['label'])), 'slug' => sanitize_title($term['label'] . '-cat'),]
406 );
407 update_term_meta($new_term['term_id'], 'blm_key', $term['blm']);
408 update_term_meta($new_term['term_id'], 'expert_agent_key', $term['expert_agent']);
409 update_term_meta($new_term['term_id'], 'dezrez_key', $term['dezrez']);
410 update_term_meta($new_term['term_id'], 'blm_export_key', $term['blm_export_key']);
411 // update_term_meta($new_term['term_id'], 'zpg_export_key', $term['zpg_export']);
412 }
413 }
414 elseif(isset($_GET['updatetermmeta'])) {
415 update_term_meta($term_exists['term_id'], 'blm_key', $term['blm']);
416 update_term_meta($term_exists['term_id'], 'expert_agent_key', $term['expert_agent']);
417 update_term_meta($term_exists['term_id'], 'dezrez_key', $term['dezrez']);
418 update_term_meta($term_exists['term_id'], 'blm_export_key', $term['blm_export_key']);
419 // update_term_meta($term_exists['term_id'], 'zpg_export_key', $term['zpg_export']);
420 }
421 }
422 }
423
424 foreach(self::$media_taxonomies as $taxonomy) {
425 register_taxonomy(
426 $taxonomy['name'],
427 'attachment',
428 ['label' => __( $taxonomy['label'] ), 'public' => true, 'rewrite' => false, 'hierarchical' => true,]
429 );
430 foreach($taxonomy['terms'] as $key => $term) {
431 $term_exists = term_exists($term['label'], $taxonomy['name']);
432 if ($term_exists === 0 || $term_exists === null) {
433 if(!empty($term['label'])) {
434 $new_term = wp_insert_term(
435 $term['label'], // the term
436 $taxonomy['name'], // the taxonomy
437 ['description'=> ucfirst(strtolower($term['label'])), 'slug' => sanitize_title($term['label']),]
438 );
439 add_term_meta($new_term['term_id'], 'blm_key', $term['blm'], true);
440 add_term_meta($new_term['term_id'], 'expert_agent_key', $term['expert_agent'], true);
441 }
442 }
443 }
444 }
445 }
446
447 /**
448 * Register our plugin admin javascript
449 * @access private
450 * @static
451 * @final
452 */
453 final public static function admin_enqueue_scripts ($hook)
454 {
455 wp_enqueue_script( 'psbootstrap-js', PSBOOTSTRAP_PLUGIN_URL . 'assets/js/plugin.js?v='.time());
456 }
457
458 /**
459 * Remove attachments that are no longer attached to a post
460 * @var integer $post_id the ID column from the wp_post table for the row being checked
461 * @access public
462 * @static
463 * @final
464 */
465 final public static function clean_unused_images ($post_id)
466 {
467 if((!isset($post_id)) || ($post_id == 0) || (is_array($post_id))) {
468 return;
469 } else {
470 $attachments = get_posts( [
471 'post_type' => 'attachment',
472 'posts_per_page' => -1,
473 'post_status' => 'any',
474 'post_parent' => $post_id
475 ] );
476 foreach ( $attachments as $attachment ) {
477 if ( false === wp_delete_attachment( $attachment->ID ) ) {
478 // Log failure to delete attachment.
479 }
480 }
481 }
482 }
483
484 /**
485 * Receive a postmeta update via ajax hook and process it
486 * @access public
487 * @static
488 * @final
489 */
490 final public static function ajax_postmeta_function()
491 {
492 if(isset($_POST['post_id']) && isset($_POST['meta_key'])&& isset($_POST['meta_value'])) {
493 $post_id = $_POST['post_id'];
494 $meta_key = $_POST['meta_key'];
495 $meta_value = $_POST['meta_value'];
496 update_post_meta($post_id, $meta_key, $meta_value);
497 die($meta_key . ' updated.');
498 } else {
499 var_dump($_POST);
500 die('FAILED');
501 }
502 }
503
504 /**
505 * Get the post coordinates for a given post ID
506 * @var array $query The WP Query
507 * @access public
508 * @static
509 * @final
510 */
511 public static function get_post_coordinates ($postID)
512 {
513 global $wpdb;
514 $sql = "SELECT lat,lng FROM {$wpdb->prefix}post_coordinates WHERE post_id = '{$postID}'";
515 return $wpdb->get_row($sql);
516 }
517
518 /**
519 * The array to set up our taxonomies
520 * @var array
521 * @static
522 * @access private
523 */
524 private static $taxonomies = [
525 // Trans Type
526 ['name' => 'trans_type_id',
527 'label' => 'Transaction Type',
528 'terms' => [['label' => 'Resale', 'blm' => 1, 'blm_export_key' => 1, 'dezrez' => 1, 'expert_agent' => ''],
529 ['label' => 'Lettings', 'blm' => 2, 'blm_export_key' => 2, 'dezrez' => 2, 'expert_agent' => ''],]],
530
531 // Status
532 ['name' => 'status_id',
533 'label' => 'Status',
534 'terms' => [['label' => 'Available', 'blm' => 0, 'blm_export_key' => 0, 'dezrez' => 0, 'expert_agent' => ''],
535 ['label' => 'SSTC', 'blm' => 1, 'blm_export_key' => 1, 'dezrez' => 2, 'expert_agent' => ''],
536 ['label' => 'SSTCM', 'blm' => 2, 'blm_export_key' => 2, 'dezrez' => '', 'expert_agent' => ''],
537 ['label' => 'Under Offer', 'blm' => 3, 'blm_export_key' => 3, 'dezrez' => 3, 'expert_agent' => ''],
538 ['label' => 'Reserved', 'blm' => 4, 'blm_export_key' => 4, 'dezrez' => 4, 'expert_agent' => ''],
539 ['label' => 'Let Agreed', 'blm' => 5, 'blm_export_key' => 5, 'dezrez' => 5, 'expert_agent' => ''],
540 ['label' => 'Sold', 'blm' => 6, 'blm_export_key' => 6, 'dezrez' => 6, 'expert_agent' => ''],
541 ['label' => 'Let', 'blm' => 7, 'blm_export_key' => 7, 'dezrez' => 7, 'expert_agent' => ''],
542 ['label' => 'Reduced', 'blm' => 7, 'blm_export_key' => 0, 'dezrez' => 1, 'expert_agent' => ''],
543
544 ]],
545
546 // Price Qualifier
547 ['name' => 'price_qualifier',
548 'label' => 'Price Qualifier',
549 'terms' => [['label' => 'Default', 'blm' => 0, 'blm_export_key' => 0, 'dezrez' => 0, 'expert_agent' => ''],
550 ['label' => 'POA', 'blm' => 1, 'blm_export_key' => 1, 'dezrez' => 0, 'expert_agent' => ''],
551 ['label' => 'Guide Price', 'blm' => 2, 'blm_export_key' => 2, 'dezrez' => 0, 'expert_agent' => ''],
552 ['label' => 'Fixed Price', 'blm' => 3, 'blm_export_key' => 3, 'dezrez' => 0, 'expert_agent' => ''],
553 ['label' => 'Offers in Excess of', 'blm' => 4, 'blm_export_key' => 4, 'dezrez' => 0, 'expert_agent' => ''],
554 ['label' => 'OIRO', 'blm' => 5, 'dezrez' => 0, 'blm_export_key' => 5, 'expert_agent' => ''],
555 ['label' => 'Sale by Tender', 'blm' => 6, 'blm_export_key' => 6, 'dezrez' => 0, 'expert_agent' => ''],
556 ['label' => 'From', 'blm' => 7, 'blm_export_key' => 7, 'dezrez' => 0, 'expert_agent' => ''],
557 ['label' => 'Shared Ownership', 'blm' => 9, 'blm_export_key' => 9, 'dezrez' => 0, 'expert_agent' => ''],
558 ['label' => 'Offers Over', 'blm' => 10, 'blm_export_key' => 10, 'dezrez' => 0, 'expert_agent' => ''],
559 ['label' => 'Part Buy Part Rent', 'blm' => 11, 'blm_export_key' => 11, 'dezrez' => 0, 'expert_agent' => ''],
560 ['label' => 'Shared Equity', 'blm' => 12, 'blm_export_key' => 12, 'dezrez' => 0, 'expert_agent' => ''],]],
561
562 // Property Type
563 ['name' => 'prop_sub_id',
564 'label' => 'Property Type',
565 'terms' => [['label' => 'Not Specified', 'blm' => 0, 'blm_export_key' => 0, 'dezrez' => 0, 'expert_agent' => ''],
566 ['label' => 'Terraced', 'blm' => 1, 'dezrez' => 1, 'blm_export_key' => 1, 'expert_agent' => ''],
567 ['label' => 'Mid Terrace', 'blm' => '', 'blm_export_key' => 1, 'dezrez' => 3, 'expert_agent' => ''],
568 ['label' => 'End of Terrace', 'blm' => 2, 'blm_export_key' => 2, 'dezrez' => 2, 'expert_agent' => ''],
569 ['label' => 'Semi-Detached', 'blm' => 3, 'blm_export_key' => 3, 'dezrez' => 4, 'expert_agent' => ''],
570 ['label' => 'Detached', 'blm' => 4, 'blm_export_key' => 4, 'dezrez' => 5, 'expert_agent' => ''],
571 ['label' => 'Remote Detached', 'blm' => '', 'blm_export_key' => 4, 'dezrez' => 6, 'expert_agent' => ''],
572 ['label' => 'End Link', 'blm' => '', 'blm_export_key' => 21, 'dezrez' => 7, 'expert_agent' => ''],
573 ['label' => 'Mid Link', 'blm' => '', 'blm_export_key' => 21, 'dezrez' => 8, 'expert_agent' => ''],
574 ['label' => 'Mews', 'blm' => 5, 'blm_export_key' => 5, 'dezrez' => 42, 'expert_agent' => ''],
575 ['label' => 'Cluster House', 'blm' => 6, 'blm_export_key' => 6, 'dezrez' => 56, 'expert_agent' => ''],
576 ['label' => 'Ground Flat', 'blm' => 7, 'blm_export_key' => 7, 'dezrez' => '', 'expert_agent' => ''],
577 ['label' => 'Ground Floor Purpose Built Flat', 'blm' => '', 'blm_export_key' => 7, 'dezrez' => 43, 'expert_agent' => ''],
578 ['label' => 'Ground Floor Converted Flat', 'blm' => '', 'blm_export_key' => 7, 'dezrez' => 46, 'expert_agent' => ''],
579 ['label' => 'Flat', 'blm' => 8, 'blm_export_key' => 8, 'dezrez' => 9, 'expert_agent' => ''],
580 ['label' => 'Studio', 'blm' => 9, 'blm_export_key' => 9, 'dezrez' => 67, 'expert_agent' => ''],
581 ['label' => 'Studio Apartment', 'blm' => '', 'blm_export_key' => 9, 'dezrez' => 59, 'expert_agent' => ''],
582 ['label' => 'Bedsit', 'blm' => '', 'blm_export_key' => 9, 'dezrez' => 72, 'expert_agent' => ''],
583 ['label' => 'Ground Maisonette', 'blm' => 10, 'blm_export_key' => 10, 'dezrez' => 49, 'expert_agent' => ''],
584 ['label' => 'First Floor Maisonette', 'blm' => '', 'blm_export_key' => 11, 'dezrez' => 50, 'expert_agent' => ''],
585 ['label' => 'Maisonette', 'blm' => 11, 'blm_export_key' => 11, 'dezrez' => 68, 'expert_agent' => ''],
586 ['label' => 'Bungalow', 'blm' => 12, 'blm_export_key' => 12, 'dezrez' => '', 'expert_agent' => ''],
587 ['label' => 'Terraced Bungalow', 'blm' => 13, 'blm_export_key' => 13, 'dezrez' => 11, 'expert_agent' => ''],
588 ['label' => 'End Terraced Bungalow', 'blm' => '', 'blm_export_key' => 13, 'dezrez' => 12, 'expert_agent' => ''],
589 ['label' => 'Mid Terraced Bungalow', 'blm' => '', 'blm_export_key' => 13, 'dezrez' => 13, 'expert_agent' => ''],
590 ['label' => 'Semi-Detached Bungalow', 'blm' => 14, 'blm_export_key' => 14, 'dezrez' => 14, 'expert_agent' => ''],
591 ['label' => 'Detached Bungalow', 'blm' => 15, 'blm_export_key' => 15, 'dezrez' => 15, 'expert_agent' => ''],
592 ['label' => 'Remote Detached Bungalow', 'blm' => '', 'blm_export_key' => 15, 'dezrez' => 16, 'expert_agent' => ''],
593 ['label' => 'End Link Bungalow', 'blm' => '', 'blm_export_key' => 15, 'dezrez' => 17, 'expert_agent' => ''],
594 ['label' => 'Mid Link Bungalow', 'blm' => '', 'blm_export_key' => 15, 'dezrez' => 18, 'expert_agent' => ''],
595 ['label' => 'Mobile Home', 'blm' => 16, 'blm_export_key' => 16, 'dezrez' => 73, 'expert_agent' => ''],
596 ['label' => 'Hotel', 'blm' => 17, 'blm_export_key' => 17, 'dezrez' => '', 'expert_agent' => ''],
597 ['label' => 'Guest House', 'blm' => 18, 'blm_export_key' => 18, 'dezrez' => '', 'expert_agent' => ''],
598 ['label' => 'Commercial Property', 'blm' => 19, 'blm_export_key' => 19, 'dezrez' => 70, 'expert_agent' => ''],
599 ['label' => 'Business', 'blm' => '', 'blm_export_key' => 19, 'dezrez' => 60, 'expert_agent' => ''],
600 ['label' => 'Land', 'blm' => 20, 'blm_export_key' => 20, 'dezrez' => '', 'expert_agent' => ''],
601 ['label' => 'Link Detached House', 'blm' => 21, 'blm_export_key' => 21, 'dezrez' => 66, 'expert_agent' => ''],
602 ['label' => 'Town House', 'blm' => 22, 'blm_export_key' => 22, 'dezrez' => '', 'expert_agent' => ''],
603 ['label' => 'Terraced Town House', 'blm' => '', 'blm_export_key' => 22, 'dezrez' => 25, 'expert_agent' => ''],
604 ['label' => 'End Terrace Town House', 'blm' => '', 'blm_export_key' => 22, 'dezrez' => 26, 'expert_agent' => ''],
605 ['label' => 'Mid Terrace Town House', 'blm' => '', 'blm_export_key' => 22, 'dezrez' => 27, 'expert_agent' => ''],
606 ['label' => 'Semi-Detached Town House', 'blm' => '', 'blm_export_key' => 22, 'dezrez' => 28, 'expert_agent' => ''],
607 ['label' => 'Detached Town House', 'blm' => '', 'blm_export_key' => 22, 'dezrez' => 29, 'expert_agent' => ''],
608 ['label' => 'Corner Town House', 'blm' => '', 'blm_export_key' => 22, 'dezrez' => 61, 'expert_agent' => ''],
609 ['label' => 'Cottage', 'blm' => 23, 'blm_export_key' => 23, 'dezrez' => '', 'expert_agent' => ''],
610 ['label' => 'Terraced Cottage', 'blm' => '', 'blm_export_key' => 23, 'dezrez' => 19, 'expert_agent' => ''],
611 ['label' => 'End Terrace Cottage', 'blm' => '', 'blm_export_key' => 23, 'dezrez' => 20, 'expert_agent' => ''],
612 ['label' => 'Mid Terrace Cottage', 'blm' => '', 'blm_export_key' => 23, 'dezrez' => 21, 'expert_agent' => ''],
613 ['label' => 'Semi-Detached Cottage', 'blm' => '', 'blm_export_key' => 23, 'dezrez' => 22, 'expert_agent' => ''],
614 ['label' => 'Detached Cottage', 'blm' => '', 'blm_export_key' => 23, 'dezrez' => 23, 'expert_agent' => ''],
615 ['label' => 'Remote Detached Cottage', 'blm' => '', 'blm_export_key' => 23, 'dezrez' => 24, 'expert_agent' => ''],
616 ['label' => 'Chalet', 'blm' => 24, 'blm_export_key' => 24, 'dezrez' => '', 'expert_agent' => ''],
617 ['label' => 'Chalet Terraced', 'blm' => '', 'blm_export_key' => 24, 'dezrez' => 35, 'expert_agent' => ''],
618 ['label' => 'Chalet End Terrace', 'blm' => '', 'blm_export_key' => 24, 'dezrez' => 36, 'expert_agent' => ''],
619 ['label' => 'Chalet Mid Terrace', 'blm' => '', 'blm_export_key' => 24, 'dezrez' => 37, 'expert_agent' => ''],
620 ['label' => 'Chalet Semi-Detached', 'blm' => '', 'blm_export_key' => 24, 'dezrez' => 38, 'expert_agent' => ''],
621 ['label' => 'Chalet Detached', 'blm' => '', 'blm_export_key' => 24, 'dezrez' => 39, 'expert_agent' => ''],
622 ['label' => 'House', 'blm' => 26, 'blm_export_key' => 0, 'dezrez' => 0, 'expert_agent' => ''],
623 ['label' => 'Villa', 'blm' => 27, 'blm_export_key' => 27, 'dezrez' => '', 'expert_agent' => ''],
624 ['label' => 'Apartment', 'blm' => 28, 'blm_export_key' => 28, 'dezrez' => 10, 'expert_agent' => ''],
625 ['label' => 'Apartment (Low Density)', 'blm' => '', 'blm_export_key' => 28, 'dezrez' => 58, 'expert_agent' => ''],
626 ['label' => 'Penthouse', 'blm' => 29, 'blm_export_key' => 29, 'dezrez' => 51, 'expert_agent' => ''],
627 ['label' => 'Finca', 'blm' => 30, 'blm_export_key' => 30, 'dezrez' => 0, 'expert_agent' => ''],
628 ['label' => 'Barn Conversion', 'blm' => 43, 'blm_export_key' => 43, 'dezrez' => '', 'expert_agent' => ''],
629 ['label' => 'Barn Conversion Detached', 'blm' => '', 'blm_export_key' => 43, 'dezrez' => 40, 'expert_agent' => ''],
630 ['label' => 'Barn Conversion Remote Detached', 'blm' => '', 'blm_export_key' => 43, 'dezrez' => 41, 'expert_agent' => ''],
631 ['label' => 'Barn Conversion Mews Style', 'blm' => '', 'blm_export_key' => 43, 'dezrez' => 42, 'expert_agent' => ''],
632 ['label' => 'Serviced Apartments', 'blm' => 44, 'blm_export_key' => 44, 'dezrez' => 0, 'expert_agent' => ''],
633 ['label' => 'Parking', 'blm' => 45, 'blm_export_key' => 45, 'dezrez' => 0, 'expert_agent' => ''],
634 ['label' => 'Sheltered Housing', 'blm' => 46, 'blm_export_key' => 46, 'dezrez' => 0, 'expert_agent' => ''],
635 ['label' => 'Retirement Property', 'blm' => 47, 'blm_export_key' => 47, 'dezrez' => 71, 'expert_agent' => ''],
636 ['label' => 'House Share', 'blm' => 48, 'blm_export_key' => 48, 'dezrez' => '', 'expert_agent' => ''],
637 ['label' => 'Flat Share', 'blm' => 49, 'blm_export_key' => 49, 'dezrez' => '', 'expert_agent' => ''],
638 ['label' => 'Garages', 'blm' => 51, 'blm_export_key' => 51, 'dezrez' => '', 'expert_agent' => ''],
639 ['label' => 'Farm House', 'blm' => 52, 'blm_export_key' => 52, 'dezrez' => '', 'expert_agent' => ''],
640 ['label' => 'Equestrian', 'blm' => 53, 'blm_export_key' => 53, 'dezrez' => '', 'expert_agent' => ''],
641 ['label' => 'Duplex', 'blm' => 56, 'blm_export_key' => 56, 'dezrez' => 52, 'expert_agent' => ''],
642 ['label' => 'Triplex', 'blm' => 59, 'blm_export_key' => 59, 'dezrez' => '', 'expert_agent' => ''],
643 ['label' => 'Longere', 'blm' => 62, 'blm_export_key' => 62, 'dezrez' => '', 'expert_agent' => ''],
644 ['label' => 'Gite', 'blm' => 65, 'blm_export_key' => 65, 'dezrez' => '', 'expert_agent' => ''],
645 ['label' => 'Barn', 'blm' => 68, 'blm_export_key' => 68, 'dezrez' => '', 'expert_agent' => ''],
646 ['label' => 'Trulli', 'blm' => 71, 'blm_export_key' => 71, 'dezrez' => '', 'expert_agent' => ''],
647 ['label' => 'Mill', 'blm' => 74, 'blm_export_key' => 74, 'dezrez' => '', 'expert_agent' => ''],
648 ['label' => 'Ruins', 'blm' => 77, 'blm_export_key' => 77, 'dezrez' => '', 'expert_agent' => ''],
649 ['label' => 'Restaurant', 'blm' => 80, 'blm_export_key' => 80, 'dezrez' => '', 'expert_agent' => ''],
650 ['label' => 'Cafe', 'blm' => 83, 'blm_export_key' => 83, 'dezrez' => '', 'expert_agent' => ''],
651 ['label' => 'Mill', 'blm' => 86, 'blm_export_key' => 86, 'dezrez' => '', 'expert_agent' => ''],
652 ['label' => 'Trulli', 'blm' => 89, 'blm_export_key' => 89, 'dezrez' => '', 'expert_agent' => ''],
653 ['label' => 'Castle', 'blm' => 92, 'blm_export_key' => 92, 'dezrez' => '', 'expert_agent' => ''],
654 ['label' => 'Village House', 'blm' => 95, 'blm_export_key' => 95, 'dezrez' => 65, 'expert_agent' => ''],
655 ['label' => 'Cave House', 'blm' => 101, 'blm_export_key' => 101, 'dezrez' => '', 'expert_agent' => ''],
656 ['label' => 'Cortijo', 'blm' => 104, 'blm_export_key' => 104, 'dezrez' => '', 'expert_agent' => ''],
657 ['label' => 'Farm Land', 'blm' => 107, 'blm_export_key' => 107, 'dezrez' => '', 'expert_agent' => ''],
658 ['label' => 'Plot', 'blm' => 110, 'blm_export_key' => 110, 'dezrez' => 57, 'expert_agent' => ''],
659 ['label' => 'Country House', 'blm' => 113, 'blm_export_key' => 113, 'dezrez' => '', 'expert_agent' => ''],
660 ['label' => 'Country House (Detached)', 'blm' => '', 'blm_export_key' => 113, 'dezrez' => 30, 'expert_agent' => ''],
661 ['label' => 'Country House (North Wing)', 'blm' => '', 'blm_export_key' => 113, 'dezrez' => 31, 'expert_agent' => ''],
662 ['label' => 'Country House (South Wing)', 'blm' => '', 'blm_export_key' => 113, 'dezrez' => 32, 'expert_agent' => ''],
663 ['label' => 'Country House (East Wing)', 'blm' => '', 'blm_export_key' => 113, 'dezrez' => 33, 'expert_agent' => ''],
664 ['label' => 'Country House (West Wing)', 'blm' => '', 'blm_export_key' => 113, 'dezrez' => 34, 'expert_agent' => ''],
665 ['label' => 'Stone House', 'blm' => 116, 'blm_export_key' => 116, 'dezrez' => '', 'expert_agent' => ''],
666 ['label' => 'Caravan', 'blm' => 117, 'blm_export_key' => 117, 'dezrez' => '', 'expert_agent' => ''],
667 ['label' => 'Lodge', 'blm' => 118, 'blm_export_key' => 118, 'dezrez' => '', 'expert_agent' => ''],
668 ['label' => 'Log Cabin', 'blm' => 119, 'blm_export_key' => 119, 'dezrez' => '', 'expert_agent' => ''],
669 ['label' => 'Manor House', 'blm' => 120, 'blm_export_key' => 120, 'dezrez' => '', 'expert_agent' => ''],
670 ['label' => 'Mansion', 'blm' => '', 'blm_export_key' => 120, 'dezrez' => 53, 'expert_agent' => ''],
671 ['label' => 'Stately Home', 'blm' => 121, 'blm_export_key' => 121, 'dezrez' => '', 'expert_agent' => ''],
672 ['label' => 'Off-Plan', 'blm' => 125, 'blm_export_key' => 125, 'dezrez' => '', 'expert_agent' => ''],
673 ['label' => 'Semi-detached Villa', 'blm' => 128, 'blm_export_key' => 128, 'dezrez' => 64, 'expert_agent' => ''],
674 ['label' => 'Detached Villa', 'blm' => 131, 'blm_export_key' => 131, 'dezrez' => 62, 'expert_agent' => ''],
675 ['label' => 'Villa Link-Detached', 'blm' => '', 'blm_export_key' => 131, 'dezrez' => 63, 'expert_agent' => ''],
676 ['label' => 'Bar', 'blm' => 134, 'blm_export_key' => 134, 'dezrez' => '', 'expert_agent' => ''],
677 ['label' => 'Shop', 'blm' => 137, 'blm_export_key' => 137, 'dezrez' => '', 'expert_agent' => ''],
678 ['label' => 'Riad', 'blm' => 140, 'blm_export_key' => 140, 'dezrez' => '', 'expert_agent' => ''],
679 ['label' => 'House Boat', 'blm' => 141, 'blm_export_key' => 141, 'dezrez' => '', 'expert_agent' => ''],
680 ['label' => 'Hotel Room', 'blm' => 142, 'blm_export_key' => 142, 'dezrez' => '', 'expert_agent' => ''],
681 ['label' => 'Block of Apartments', 'blm' => 143, 'blm_export_key' => 143, 'dezrez' => '', 'expert_agent' => ''],
682 ['label' => 'Private Halls', 'blm' => 144, 'blm_export_key' => 144, 'dezrez' => '', 'expert_agent' => ''],
683 ['label' => 'Office', 'blm' => 178, 'blm_export_key' => 178, 'dezrez' => '', 'expert_agent' => ''],
684 ['label' => 'Business Park', 'blm' => 181, 'blm_export_key' => 181, 'dezrez' => '', 'expert_agent' => ''],
685 ['label' => 'Serviced Office', 'blm' => 184, 'blm_export_key' => 184, 'dezrez' => '', 'expert_agent' => ''],
686 ['label' => 'Retail Property (high street)', 'blm' => 187, 'blm_export_key' => 187, 'dezrez' => '', 'expert_agent' => ''],
687 ['label' => 'Retail Property (out of town)', 'blm' => 190, 'blm_export_key' => 190, 'dezrez' => '', 'expert_agent' => ''],
688 ['label' => 'Convenience Store', 'blm' => 193, 'blm_export_key' => 193, 'dezrez' => '', 'expert_agent' => ''],
689 ['label' => 'Garage', 'blm' => 196, 'blm_export_key' => 196, 'dezrez' => '', 'expert_agent' => ''],
690 ['label' => 'Hairdresser / Barber Shop', 'blm' => 199, 'blm_export_key' => 199, 'dezrez' => '', 'expert_agent' => ''],
691 ['label' => 'Petrol Station', 'blm' => 205, 'blm_export_key' => 205, 'dezrez' => '', 'expert_agent' => ''],
692 ['label' => 'Post Office', 'blm' => 208, 'blm_export_key' => 208, 'dezrez' => '', 'expert_agent' => ''],
693 ['label' => 'Pub', 'blm' => 211, 'blm_export_key' => 211, 'dezrez' => '', 'expert_agent' => ''],
694 ['label' => 'Workshop', 'blm' => 214, 'blm_export_key' => 214, 'dezrez' => '', 'expert_agent' => ''],
695 ['label' => 'Distribution Warehouse', 'blm' => 217, 'blm_export_key' => 217, 'dezrez' => '', 'expert_agent' => ''],
696 ['label' => 'Factory', 'blm' => 220, 'blm_export_key' => 220, 'dezrez' => '', 'expert_agent' => ''],
697 ['label' => 'Heavy Industrial', 'blm' => 223, 'blm_export_key' => 223, 'dezrez' => '', 'expert_agent' => ''],
698 ['label' => 'Industrial Park', 'blm' => 226, 'blm_export_key' => 226, 'dezrez' => '', 'expert_agent' => ''],
699 ['label' => 'Light Industrial', 'blm' => 229, 'blm_export_key' => 229, 'dezrez' => '', 'expert_agent' => ''],
700 ['label' => 'Storage', 'blm' => 232, 'blm_export_key' => 232, 'dezrez' => '', 'expert_agent' => ''],
701 ['label' => 'Showroom', 'blm' => 235, 'blm_export_key' => 235, 'dezrez' => '', 'expert_agent' => ''],
702 ['label' => 'Warehouse', 'blm' => 238, 'blm_export_key' => 238, 'dezrez' => '', 'expert_agent' => ''],
703 ['label' => 'Land', 'blm' => 241, 'blm_export_key' => 241, 'dezrez' => '', 'expert_agent' => ''],
704 ['label' => 'Commercial Development', 'blm' => 244, 'blm_export_key' => 244, 'dezrez' => '', 'expert_agent' => ''],
705 ['label' => 'Industrial Development', 'blm' => 247, 'blm_export_key' => 247, 'dezrez' => '', 'expert_agent' => ''],
706 ['label' => 'Residential Development', 'blm' => 250, 'blm_export_key' => 250, 'dezrez' => '', 'expert_agent' => ''],
707 ['label' => 'Other', 'blm' => 253, 'blm_export_key' => 253, 'dezrez' => '', 'expert_agent' => ''],
708 ['label' => 'Data Centre', 'blm' => 256, 'blm_export_key' => 256, 'dezrez' => '', 'expert_agent' => ''],
709 ['label' => 'Farm', 'blm' => 259, 'blm_export_key' => 259, 'dezrez' => '', 'expert_agent' => ''],
710 ['label' => 'Healthcare Facility', 'blm' => 262, 'blm_export_key' => 262, 'dezrez' => '', 'expert_agent' => ''],
711 ['label' => 'Marine Property', 'blm' => 265, 'blm_export_key' => 265, 'dezrez' => '', 'expert_agent' => ''],
712 ['label' => 'Mixed Use', 'blm' => 268, 'blm_export_key' => 268, 'dezrez' => '', 'expert_agent' => ''],
713 ['label' => 'Research Facility', 'blm' => 271, 'blm_export_key' => 271, 'dezrez' => '', 'expert_agent' => ''],
714 ['label' => 'Science Park', 'blm' => 274, 'blm_export_key' => 274, 'dezrez' => '', 'expert_agent' => ''],
715 ['label' => 'Guest House', 'blm' => 277, 'blm_export_key' => 277, 'dezrez' => '', 'expert_agent' => ''],
716 ['label' => 'Hospitality', 'blm' => 280, 'blm_export_key' => 280, 'dezrez' => '', 'expert_agent' => ''],
717 ['label' => 'Leisure Facility', 'blm' => 283, 'blm_export_key' => 283, 'dezrez' => '', 'expert_agent' => ''],
718 ['label' => 'Takeaway', 'blm' => 298, 'blm_export_key' => 298,'dezrez' => '', 'expert_agent' => ''],
719 ['label' => 'Childcare Facility', 'blm' => 301, 'blm_export_key' => 301, 'dezrez' => '', 'expert_agent' => ''],
720 ['label' => 'Smallholding', 'blm' => 304, 'blm_export_key' => 304, 'dezrez' => '', 'expert_agent' => ''],
721 ['label' => 'Place of Worship', 'blm' => 307, 'blm_export_key' => 307, 'dezrez' => '', 'expert_agent' => ''],
722 ['label' => 'Trade Counter', 'blm' => 310, 'blm_export_key' => 310, 'dezrez' => '', 'expert_agent' => ''],
723 ['label' => 'Coach House', 'blm' => 511, 'blm_export_key' => 511, 'dezrez' => '', 'expert_agent' => ''],
724 ['label' => 'First Floor Purpose Built Flat', 'blm' => '', 'blm_export_key' => 8, 'dezrez' => 44, 'expert_agent' => ''],
725 ['label' => 'First Floor Converted Flat', 'blm' => '', 'blm_export_key' => 8, 'dezrez' => 47, 'expert_agent' => ''],
726 ['label' => 'Second Floor Purpose Built Flat', 'blm' => '', 'blm_export_key' => 8, 'dezrez' => 45, 'expert_agent' => ''],
727 ['label' => 'Second Floor Converted Flat', 'blm' => '', 'blm_export_key' => 8, 'dezrez' => 48, 'expert_agent' => ''],
728 ['label' => 'Shell', 'blm' => '', 'blm_export_key' => 253, 'dezrez' => 69, 'expert_agent' => ''],
729 ['label' => 'Q-Type', 'blm' => '', 'blm_export_key' => 253, 'dezrez' => 54, 'expert_agent' => ''],
730 ['label' => 'T-Type', 'blm' => '', 'blm_export_key' => 253, 'dezrez' => 55, 'expert_agent' => ''],
731 ]],
732
733 // Let Type
734 ['name' => 'let_type_id',
735 'label' => 'Let Type',
736 'terms' => [['label' => 'Not Specified', 'blm' => 0, 'blm_export_key' => 0, 'dezrez' => 0, 'expert_agent' => ''],
737 ['label' => 'Long Term', 'blm' => 1, 'blm_export_key' => 1, 'dezrez' => 0, 'expert_agent' => ''],
738 ['label' => 'Short Term', 'blm' => 2, 'blm_export_key' => 2, 'dezrez' => 0, 'expert_agent' => ''],
739 ['label' => 'Student', 'blm' => 3, 'blm_export_key' => 3, 'dezrez' => 0, 'expert_agent' => ''],
740 ['label' => 'Commercial', 'blm' => 4, 'blm_export_key' => 4, 'dezrez' => 0, 'expert_agent' => ''],]],
741
742 // Is Furnished
743 ['name' => 'let_furn_id',
744 'label' => 'Let Furnished',
745 'terms' => [['label' => 'Furnished', 'blm' => 0, 'blm_export_key' => 0, 'dezrez' => 0, 'expert_agent' => ''],
746 ['label' => 'Part Furnished', 'blm' => 1, 'blm_export_key' => 1, 'dezrez' => 0, 'expert_agent' => ''],
747 ['label' => 'Unfurnished', 'blm' => 2, 'blm_export_key' => 2, 'dezrez' => 0, 'expert_agent' => ''],
748 ['label' => 'Not Specified', 'blm' => 3, 'blm_export_key' => 3, 'dezrez' => 0, 'expert_agent' => ''],
749 ['label' => 'Furnished/Unfurnished', 'blm' => 4, 'blm_export_key' => 4, 'dezrez' => 0, 'expert_agent' => ''],]],
750
751 // Let Frequency
752 ['name' => 'let_rent_frequency',
753 'label' => 'Let Rent Frequency',
754 'terms' => [['label' => 'Weekly', 'blm' => 0, 'blm_export_key' => 0, 'dezrez' => 3, 'expert_agent' => ''],
755 ['label' => 'Monthly', 'blm' => 1, 'blm_export_key' => 1, 'dezrez' => 4, 'expert_agent' => ''],
756 ['label' => 'Quarterly', 'blm' => 2, 'blm_export_key' => 2, 'dezrez' => 5, 'expert_agent' => ''],
757 ['label' => 'Annual', 'blm' => 3, 'blm_export_key' => 3, 'dezrez' => 6, 'expert_agent' => ''],
758 ['label' => 'Daily', 'blm' => '', 'blm_export_key' => '', 'dezrez' => 2, 'expert_agent' => ''],
759 ['label' => 'Per Person Per Week', 'blm' => 4, 'blm_export_key' => 4, 'dezrez' => '', 'expert_agent' => ''],]],
760
761 // Tenure Type
762 ['name' => 'tenure_type_id',
763 'label' => 'Tenure Type',
764 'terms' => [['label' => 'Freehold', 'blm' => 1, 'blm_export_key' => 1, 'dezrez' => 3, 'expert_agent' => ''],
765 ['label' => 'Leasehold', 'blm' => 2, 'blm_export_key' => 2, 'dezrez' => 2, 'expert_agent' => ''],
766 ['label' => 'Feudal', 'blm' => 3, 'blm_export_key' => 3, 'dezrez' => 0, 'expert_agent' => ''],
767 ['label' => 'Commonhold', 'blm' => 4, 'blm_export_key' => 4, 'dezrez' => 0, 'expert_agent' => ''],
768 ['label' => 'Share of Freehold', 'blm' => 5, 'blm_export_key' => 5, 'dezrez' => 8, 'expert_agent' => ''],
769 ['label' => 'Freehold (to be confirmed)', 'blm' => '', 'blm_export_key' => 1, 'dezrez' => 5, 'expert_agent' => ''],
770 ['label' => 'Leasehold (to be confirmed)', 'blm' => '', 'blm_export_key' => 2, 'dezrez' => 4, 'expert_agent' => ''],
771 ['label' => 'To be Advised', 'blm' => '', 'blm_export_key' => 0, 'dezrez' => 6, 'expert_agent' => ''],
772 ['label' => 'Flying Freehold', 'blm' => '', 'blm_export_key' => 1, 'dezrez' => 9, 'expert_agent' => ''],
773 ['label' => 'Share of Leasehold', 'blm' => '', 'blm_export_key' => 2, 'dezrez' => 7, 'expert_agent' => ''],
774 ['label' => 'Not Applicable', 'blm' => '', 'blm_export_key' => 0, 'dezrez' => 1, 'expert_agent' => ''],
775 ['label' => 'Leasehold (Share of Freehold)', 'blm' => '', 'blm_export_key' => 2, 'dezrez' => 11, 'expert_agent' => ''],]],
776
777 // New Home
778 ['name' => 'new_home_flag',
779 'label' => 'New Home',
780 'terms' => [['label' => 'New Home', 'blm' => 'Y', 'blm_export_key' => 'Y', 'dezrez' => 0, 'expert_agent' => ''],
781 ['label' => 'Non New Home', 'blm' => 'N', 'blm_export_key' => 'N', 'dezrez' => 0, 'expert_agent' => ''],]],
782
783 // Business For Sale
784 ['name' => 'business_for_sale_flag',
785 'label' => 'Business For Sale',
786 'terms' => [['label' => 'Not A Business For Sale', 'blm' => 0, 'blm_export_key' => 0, 'dezrez' => 0, 'expert_agent' => ''],
787 ['label' => 'Business For Sale', 'blm' => 1, 'blm_export_key' => 1, 'dezrez' => 0, 'expert_agent' => ''],]],
788
789 ];
790
791 /**
792 * The array to set up our taxonomies for media files
793 * @var array
794 * @static
795 * @access private
796 */
797 private static $media_taxonomies = [
798 ['name' => 'media_type',
799 'label' => 'Media Type',
800 'terms' => [['label' => 'Image', 'blm' => 1, 'blm_export_key' => 1, 'dezrez' => 0, 'expert_agent' => ''],
801 ['label' => 'Floorplan', 'blm' => 2, 'blm_export_key' => 2, 'dezrez' => 0, 'expert_agent' => ''],
802 ['label' => 'Virtual Tour', 'blm' => 3, 'blm_export_key' => 3, 'dezrez' => 0, 'expert_agent' => ''],
803 ['label' => 'Brochure', 'blm' => 4, 'blm_export_key' => 4, 'dezrez' => 0, 'expert_agent' => ''],
804 ['label' => 'Audio Tour', 'blm' => 5, 'blm_export_key' => 5, 'dezrez' => 0, 'expert_agent' => ''],
805 ['label' => 'EPC', 'blm' => 6, 'blm_export_key' => 6, 'dezrez' => 0, 'expert_agent' => ''],
806 ['label' => 'EPC Graph', 'blm' => 7, 'blm_export_key' => 7, 'dezrez' => 0, 'expert_agent' => ''],]],
807 ];
808
809
810 /**
811 * Create attachments from gallery images
812 * @access private
813 * @static
814 * @final
815 */
816 final public static function attach_gallery_images ($post_id, $post, $update)
817 {
818
819 if($post->post_type !== 'property') {
820 return;
821 }
822
823 if(empty($_POST)) {
824 return;
825 }
826
827
828 $gallery = [];
829 $gallery['secondary'] = get_field('propertystream_gallery', $post_id);
830 $gallery['EER'] = get_field('propertystream_eer', $post_id);
831 $gallery['EIR'] = get_field('propertystream_eir', $post_id);
832 $gallery['EPC'] = get_field('propertystream_epc', $post_id);
833 $gallery['floorplan'] = get_field('propertystream_floorplan', $post_id);
834
835 $upload_dir = wp_upload_dir();
836 $upload_dir = $upload_dir['baseurl'] . '/';
837
838 $secondaryAttachments = [];
839 $eerAttachments = [];
840 $eirAttachments = [];
841 $epcAttachments = [];
842 $floorplanAttachments = [];
843 $array = [];
844
845 foreach($gallery as $key => $images) :
846 $post_content = $key;
847 if($images) :
848 foreach($images as $image) :
849
850 // $filename should be the path to a file in the upload directory.
851 $filename = str_replace($upload_dir,'',$image['url']);
852
853 // The ID of the post this attachment is for.
854 $parent_post_id = $post_id;
855
856 // Check the type of file. We'll use this as the 'post_mime_type'.
857 $filetype = wp_check_filetype( basename( $filename ), null );
858
859 // Get the path to the upload directory.
860 $wp_upload_dir = wp_upload_dir();
861
862 // Attachment title
863 $post_title = preg_replace( '/\.[^.]+$/', '', basename( $filename ) );
864 // Prepare an array of post data for the attachment.
865 $attachment = array(
866 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
867 'post_mime_type' => $filetype['type'],
868 'post_title' => $post_title,
869 'post_content' => $post_content,
870 'post_status' => 'inherit',
871 'post_type' => 'attachment'
872 );
873
874 // Check attachment exists based on it's title
875 $exists = get_page_by_title($post_title, OBJECT, 'attachment');
876 if($exists) {
877 // if post title exists then we are updating...
878 $attach_id = $exists->ID;
879 $attachment['ID'] = $attach_id;
880 wp_update_post( $attachment );
881 update_attached_file( $attach_id, $filename );
882 } else {
883 // Insert the attachment.
884 $attach_id = wp_insert_attachment( $attachment, $filename, $parent_post_id );
885
886 }
887 switch ($key) :
888 case 'secondary' :
889 array_push($secondaryAttachments, $attach_id);
890 break;
891 case 'EER' :
892 array_push($eerAttachments, $attach_id);
893 break;
894 case 'EIR' :
895 array_push($eirAttachments, $attach_id);
896 break;
897 case 'EPC' :
898 array_push($epcAttachments, $attach_id);
899 break;
900 case 'floorplan' :
901 array_push($floorplanAttachments, $attach_id);
902 break;
903 endswitch;
904
905 // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
906 require_once( ABSPATH . 'wp-admin/includes/image.php' );
907
908 // Generate the metadata for the attachment, and update the database record.
909 $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
910 wp_update_attachment_metadata( $attach_id, $attach_data );
911
912 wp_set_object_terms($attach_id, 'Image', 'media_type');
913
914 endforeach;
915 endif;
916 endforeach;
917
918 $currentAttachments = get_attached_media( 'image/jpeg', $post_id );
919 $currentAttachIds = [];
920 foreach($currentAttachments as $current) {
921 array_push($currentAttachIds, $current->ID);
922 }
923
924 $deleteIDs = array_diff($currentAttachIds,$secondaryAttachments,$eerAttachments,$eirAttachments,$epcAttachments,$floorplanAttachments);
925
926 // die(print_r($secondaryAttachments));
927
928 foreach ($deleteIDs as $id) {
929 $my_post = array(
930 'ID' => $id,
931 'post_parent' => '0',
932 );
933
934 wp_update_post( $my_post );
935 }
936 }
937
938 /**
939 * Create attachments from gallery images
940 * @access private
941 * @static
942 * @final
943 */
944 final public static function add_content_to_thumnail ($post_id, $post, $update)
945 {
946
947
948 if($post->post_type !== 'property') {
949 return;
950 }
951
952 if(empty($_POST)) {
953 return;
954 }
955
956 $post_thumbnail_id = get_post_thumbnail_id($post_id);
957
958 $attachment = array(
959 'ID' => $post_thumbnail_id,
960 'post_content' => 'primary',
961 'post_parent' => $post_id,
962 'post_type' => 'attachment'
963 );
964 wp_update_post( $attachment );
965
966 }
967
968 /**
969 * Add ACF json file with custom fields
970 *
971 * @access public
972 * @final
973 * @static
974 * @return null
975 */
976 final public static function acf_json_load_point($paths)
977 {
978 $paths[] = plugin_dir_path( __FILE__ ) . '/acf';
979 return $paths;
980 }
981
982
983 /**
984 * add custom scripts to admin to move content
985 *
986 * @final
987 * @access public
988 * @static
989 * @return null
990 */
991 final public static function acf_admin_head()
992 {
993 ?><script type="text/javascript">
994 (function($){
995 $(document).ready(function(){
996 $('.acf-field-57b42cbb43259 .acf-input').append( $('#postdivrich') );
997 $('.acf-field-57b42cea4325b .acf-input').append( $('#excerpt') );
998 });
999 })(jQuery);
1000 </script>
1001 <style type="text/css">
1002 .acf-field #wp-content-editor-tools {
1003 background: transparent;
1004 padding-top: 0;
1005 }
1006
1007 .post-type-property #postexcerpt {
1008 display:none;
1009 }
1010 </style><?php
1011 }
1012
1013
1014
1015
1016}