PluginProbe
Property Hive / 2.2.6
Property Hive v2.2.6
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / admin / settings / class-ph-settings-frontend.php

class-ph-settings-frontend.php in Property Hive 2.2.6, at includes/admin/settings/class-ph-settings-frontend.php

1,701 lines 72.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Frontend Settings
4 *
5 * @author PropertyHive
6 * @category Admin
7 * @package PropertyHive/Admin
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 if ( ! class_exists( 'PH_Settings_Frontend' ) ) :
16
17 /**
18 * PH_Settings_Frontend.
19 */
20 class PH_Settings_Frontend extends PH_Settings_Page {
21
22 /**
23 * Constructor.
24 */
25 public function __construct() {
26 $this->id = 'frontend';
27 $this->label = __( 'Frontend', 'propertyhive' );
28
29 add_action( 'admin_init', array( $this, 'check_for_reset_search_form') );
30 add_action( 'admin_init', array( $this, 'check_for_delete_search_form') );
31
32 add_filter( 'propertyhive_settings_tabs_array', array( $this, 'add_settings_page' ), 16 );
33 add_action( 'propertyhive_sections_' . $this->id, array( $this, 'output_sections' ) );
34 add_action( 'propertyhive_settings_' . $this->id, array( $this, 'output' ) );
35 add_action( 'propertyhive_settings_save_' . $this->id, array( $this, 'save' ) );
36
37 add_action( 'propertyhive_admin_field_search_forms_table', array( $this, 'search_forms_table' ) );
38 add_action( 'propertyhive_admin_field_search_form_fields', array( $this, 'search_form_fields' ) );
39 }
40
41 public function check_for_reset_search_form()
42 {
43 if ( isset($_GET['action']) && $_GET['action'] == 'resetsearchform' && isset($_GET['id']) && $_GET['id'] != '' )
44 {
45 if ( ! current_user_can( 'manage_options' ) )
46 {
47 wp_die( __( 'Sorry, you are not allowed to do this.', 'propertyhive' ) );
48 }
49
50 check_admin_referer( 'ph_reset_search_form_' . $_GET['id'] );
51
52 $current_settings = get_option( 'propertyhive_template_assistant', array() );
53
54 $current_id = ( !isset( $_GET['id'] ) ) ? '' : sanitize_title( $_GET['id'] );
55
56 $existing_search_forms = ( (isset($current_settings['search_forms'])) ? $current_settings['search_forms'] : array() );
57
58 if ( !isset($existing_search_forms[$current_id]) )
59 {
60 die("Trying to reset a non-existant search form. Please go back and try again");
61 }
62
63 if ( isset($existing_search_forms[$current_id]) )
64 {
65 $existing_search_forms[$current_id] = array();
66 }
67
68 $current_settings['search_forms'] = $existing_search_forms;
69
70 update_option( 'propertyhive_template_assistant', $current_settings );
71 }
72 }
73
74 public function check_for_delete_search_form()
75 {
76 if ( isset($_GET['action']) && $_GET['action'] == 'deletesearchform' && isset($_GET['id']) && $_GET['id'] != '' && $_GET['id'] != 'default' )
77 {
78 if ( ! current_user_can( 'manage_options' ) )
79 {
80 wp_die( __( 'Sorry, you are not allowed to do this.', 'propertyhive' ) );
81 }
82
83 check_admin_referer( 'ph_delete_search_form_' . $_GET['id'] );
84
85 $current_settings = get_option( 'propertyhive_template_assistant', array() );
86
87 $current_id = ( !isset( $_GET['id'] ) ) ? '' : sanitize_title( $_GET['id'] );
88
89 $existing_search_forms = ( (isset($current_settings['search_forms'])) ? $current_settings['search_forms'] : array() );
90
91 if ( !isset($existing_search_forms[$current_id]) )
92 {
93 die("Trying to delete a non-existant search form. Please go back and try again");
94 }
95
96 if ( isset($existing_search_forms[$current_id]) )
97 {
98 unset($existing_search_forms[$current_id]);
99 }
100
101 $current_settings['search_forms'] = $existing_search_forms;
102
103 update_option( 'propertyhive_template_assistant', $current_settings );
104 }
105 }
106
107 /**
108 * Get sections.
109 *
110 * @return array
111 */
112 public function get_sections() {
113 $sections = array(
114 '' => __( 'Search Results', 'propertyhive' ),
115 'search-forms' => __( 'Search Forms', 'propertyhive' ),
116 'flags' => __( 'Flags', 'propertyhive' ),
117 );
118
119 return apply_filters( 'propertyhive_get_sections_' . $this->id, $sections );
120 }
121
122 /**
123 * Get settings array.
124 *
125 * @return array
126 */
127 public function get_settings() {
128
129 $current_settings = get_option( 'propertyhive_template_assistant', array() );
130
131 $settings = array(
132
133 array( 'title' => __( 'Search Results Page Layout', 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'template_assistant_search_results_settings' )
134
135 );
136
137 $settings[] = array(
138 'title' => __( 'Default Sort Order', 'propertyhive' ),
139 'id' => 'search_result_default_order',
140 'type' => 'select',
141 'default' => ( isset($current_settings['search_result_default_order']) ? $current_settings['search_result_default_order'] : ''),
142 'options' => array(
143 '' => 'Price Descending (' . __( 'default', 'propertyhive') . ')',
144 'price-asc' => 'Price Ascending',
145 'date' => 'Date Added',
146 )
147 );
148
149 $settings[] = array(
150 'title' => __( 'Properties Per Row', 'propertyhive' ),
151 'id' => 'search_result_columns',
152 'type' => 'select',
153 'default' => ( isset($current_settings['search_result_columns']) ? $current_settings['search_result_columns'] : '1'),
154 'options' => array(
155 '1' => '1 (' . __( 'default', 'propertyhive') . ')',
156 '2' => '2',
157 '3' => '3',
158 '4' => '4',
159 )
160 );
161
162 $settings[] = array(
163 'title' => __( 'Result Layout', 'propertyhive' ),
164 'id' => 'search_result_layout',
165 'type' => 'select',
166 'default' => ( isset($current_settings['search_result_layout']) ? $current_settings['search_result_layout'] : '1'),
167 'options' => array(
168 '1' => 'List Layout 1 (default)',
169 '2' => 'List Layout 2 (card)',
170 )
171 );
172
173 $search_result_fields = array( 'price', 'floor_area', 'summary', 'actions' );
174 if ( isset($current_settings['search_result_fields']) && is_array($current_settings['search_result_fields']) )
175 {
176 if ( !empty($current_settings['search_result_fields']) )
177 {
178 $search_result_fields = $current_settings['search_result_fields'];
179 }
180 else
181 {
182 $search_result_fields = array();
183 }
184 }
185
186 $fields = array(
187 array( 'id' => 'price', 'label' => 'Price / Rent' ),
188 array( 'id' => 'floor_area', 'label' => 'Floor Area (commercial only)' ),
189 array( 'id' => 'summary', 'label' => 'Summary Description' ),
190 array( 'id' => 'actions', 'label' => 'Actions (i.e. More Details Button)' ),
191 array( 'id' => 'rooms', 'label' => 'Rooms Counts' ),
192 array( 'id' => 'availability', 'label' => 'Availability' ),
193 array( 'id' => 'property_type', 'label' => 'Property Type' ),
194 array( 'id' => 'available_date', 'label' => 'Available Date (lettings only)' ),
195 );
196 $custom_field_selected = false;
197 if ( isset($current_settings['custom_fields']) && is_array($current_settings['custom_fields']) && !empty($current_settings['custom_fields']) )
198 {
199 $label = '<select name="search_result_fields_custom_field"><option value="">Custom Field...</option>';
200 foreach ( $current_settings['custom_fields'] as $custom_field )
201 {
202 $label .= '<option value="custom_field' . $custom_field['field_name'] . '"';
203 if ( in_array('custom_field' . $custom_field['field_name'], $search_result_fields) )
204 {
205 $label .= ' selected';
206 $custom_field_selected = true;
207 }
208 $label .= '>' . $custom_field['field_label'] . '</option>';
209 }
210 $label .= '</select>';
211
212 $fields[] = array( 'id' => 'custom_field', 'label' => $label );
213 }
214
215 // Need to sort order to match what's saved
216 foreach ( $search_result_fields as $j => $search_result_field )
217 {
218 foreach ( $fields as $i => $field )
219 {
220 if ( $field['id'] == $search_result_field || ( $field['id'] == 'custom_field' && substr($search_result_field, 0, 12) == 'custom_field' ) )
221 {
222 $fields[$i]['order'] = $j;
223 }
224 }
225 }
226 foreach ( $fields as $i => $field )
227 {
228 if ( !isset($field['order']) )
229 {
230 $fields[$i]['order'] = $i + 99;
231 }
232 }
233
234 // order $fields by 'order' key
235 $sorter = array();
236 $ret = array();
237 reset($fields);
238 foreach ($fields as $ii => $va)
239 {
240 $sorter[$ii] = $va['order'];
241 }
242 asort($sorter);
243 foreach ($sorter as $ii => $va)
244 {
245 $ret[$ii] = $fields[$ii];
246 }
247 $fields = $ret;
248
249 $html = '<span class="form-field-options" id="sortable_options">';
250 foreach ( $fields as $field )
251 {
252 $html .= '<span style="display:block; padding:3px 0;">
253 <i class="fa fa-reorder" style="cursor:pointer; opacity:0.3"></i> &nbsp;
254 <input type="checkbox" name="search_result_fields[]" value="' . $field['id'] . '"';
255 if ( in_array($field['id'], $search_result_fields) || ( $field['id'] == 'custom_field' && $custom_field_selected ) )
256 {
257 $html .= ' checked';
258 }
259 $html .= '>
260 ' . $field['label'] . '
261 </span>';
262 }
263 $html .= '</span>
264
265 <script>
266 jQuery(document).ready(function($)
267 {
268 $( "#sortable_options" )
269 .sortable({
270 axis: "y",
271 handle: "i",
272 stop: function( event, ui )
273 {
274 // IE doesn\'t register the blur when sorting
275 // so trigger focusout handlers to remove .ui-state-focus
276 //ui.item.children( "h3" ).triggerHandler( "focusout" );
277
278 // Refresh accordion to handle new order
279 //$( this ).accordion( "refresh" );
280 },
281 update: function( event, ui )
282 {
283 // Update hidden fields
284 var fields_order = $(this).sortable(\'toArray\');
285
286 //$(\'#active_fields_order\').val( fields_order.join("|") );
287 }
288 });
289 });
290 </script>';
291
292 $settings[] = array(
293 'title' => __( 'Fields Shown', 'propertyhive' ),
294 'type' => 'html',
295 'html' => $html
296 );
297
298 if ( get_option('propertyhive_images_stored_as', '') != 'urls' )
299 {
300 $image_sizes = get_intermediate_image_sizes();
301 $image_size_options = array();
302 foreach ( $image_sizes as $image_size )
303 {
304 $image_size_options[$image_size] = $image_size;
305 }
306
307 $settings[] = array(
308 'title' => __( 'Image Size Used', 'propertyhive' ),
309 'id' => 'search_result_image_size',
310 'type' => 'select',
311 'default' => ( isset($current_settings['search_result_image_size']) ? $current_settings['search_result_image_size'] : 'medium'),
312 'options' => $image_size_options
313 );
314 }
315
316 $columns_1_css = file_get_contents(PH()->plugin_path() . '/assets/css/search-results-layouts/columns-1.css');
317 $columns_2_css = file_get_contents(PH()->plugin_path() . '/assets/css/search-results-layouts/columns-2.css');
318 $columns_3_css = file_get_contents(PH()->plugin_path() . '/assets/css/search-results-layouts/columns-3.css');
319 $columns_4_css = file_get_contents(PH()->plugin_path() . '/assets/css/search-results-layouts/columns-4.css');
320 $layout_1_css = '';
321 $layout_2_css = file_get_contents(PH()->plugin_path() . '/assets/css/search-results-layouts/content-property-2.css');
322
323 $settings[] = array(
324 'title' => __( 'Customise CSS', 'propertyhive' ),
325 'id' => 'search_result_css',
326 'type' => 'textarea',
327 'default' => ( isset($current_settings['search_result_css']) ? $current_settings['search_result_css'] : $columns_1_css . "\n\n" . $layout_1_css ),
328 'css' => 'height:200px;width:100%;',
329 );
330
331 if ( isset($current_settings['search_result_css']) && trim($current_settings['search_result_css']) != '' )
332 {
333 $settings[] = array(
334 'type' => 'html',
335 'html' => '<div id="change_warning" style="display:none; color:#900">
336 By changing the options above the CSS been regenerated. Please note that this will overwrite any customisations you\'ve previously made to the CSS.
337 </div>'
338 );
339 }
340
341 $settings[] = array(
342 'title' => __( 'Apply CSS To All Pages', 'propertyhive' ),
343 'id' => 'search_result_css_all_pages',
344 'type' => 'checkbox',
345 'default' => isset($current_settings['search_result_css_all_pages']) && $current_settings['search_result_css_all_pages'] == 'yes' ? 'yes' : '',
346 );
347
348 $settings[] = array(
349 'type' => 'html',
350 'html' => '<script>
351
352 jQuery(document).ready(function()
353 {
354 jQuery(\'#search_result_columns\').change(function()
355 {
356 generate_search_results_css();
357 });
358 jQuery(\'#search_result_layout\').change(function()
359 {
360 generate_search_results_css();
361 });
362 });
363
364 function generate_search_results_css()
365 {
366 jQuery(\'#search_result_css\').val(\'\');
367
368 jQuery(\'#change_warning\').slideDown();
369
370 var columns_css = \'\';
371 var layout_css = \'\';
372 switch ( jQuery(\'#search_result_columns\').val() )
373 {
374 case \'1\':
375 {
376 columns_css = "' . str_replace(array("\r\n", "\n"), '\n', $columns_1_css) . '";
377 break;
378 }
379 case \'2\':
380 {
381 columns_css = "' . str_replace(array("\r\n", "\n"), '\n', $columns_2_css) . '";
382 break;
383 }
384 case \'3\':
385 {
386 columns_css = "' . str_replace(array("\r\n", "\n"), '\n', $columns_3_css) . '";
387 break;
388 }
389 case \'4\':
390 {
391 columns_css = "' . str_replace(array("\r\n", "\n"), '\n', $columns_4_css) . '";
392 break;
393 }
394 }
395
396 switch ( jQuery(\'#search_result_layout\').val() )
397 {
398 case \'1\':
399 {
400 layout_css = "' . str_replace(array("\r\n", "\n"), '\n', $layout_1_css) . '";
401 break;
402 }
403 case \'2\':
404 {
405 layout_css = "' . str_replace(array("\r\n", "\n"), '\n', $layout_2_css) . '";
406 break;
407 }
408 }
409
410 jQuery(\'#search_result_css\').val( columns_css + "\n\n" + layout_css );
411 }
412
413 </script>'
414 );
415
416 $settings[] = array( 'type' => 'sectionend', 'id' => 'template_assistant_search_results_settings');
417
418 return apply_filters( 'propertyhive_get_settings_' . $this->id, $settings );
419 }
420
421 public function get_search_forms_settings()
422 {
423 $current_settings = get_option( 'propertyhive_template_assistant', array() );
424
425 $settings = array(
426
427 array( 'title' => __( 'Search Forms', 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'template_assistant_search_forms_settings' )
428
429 );
430
431 $settings[] = array(
432 'type' => 'search_forms_table',
433 );
434
435 $settings[] = array( 'type' => 'sectionend', 'id' => 'template_assistant_search_forms_settings');
436
437 return $settings;
438 }
439
440 public function get_search_form_settings()
441 {
442 global $current_section;
443
444 wp_enqueue_script( 'jquery-ui-accordion' );
445 wp_enqueue_script( 'jquery-ui-sortable' );
446
447 $current_settings = get_option( 'propertyhive_template_assistant', array() );
448
449 if ( !isset($current_settings['search_forms']) )
450 {
451 $current_settings['search_forms'] = array();
452 }
453 if ( !isset($current_settings['search_forms']['default']) )
454 {
455 $current_settings['search_forms']['default'] = array();
456 }
457
458 $current_id = ( !isset( $_REQUEST['id'] ) ) ? '' : sanitize_title( $_REQUEST['id'] );
459
460 $search_form_details = array();
461
462 if ($current_id != '')
463 {
464 $search_forms = $current_settings['search_forms'];
465
466 if (isset($search_forms[$current_id]))
467 {
468 $search_form_details = $search_forms[$current_id];
469 }
470 else
471 {
472 die('Trying to edit a search form which does not exist. Please go back and try again.');
473 }
474 }
475
476 $settings = array(
477
478 array( 'title' => __( ( $current_section == 'addsearchform' ? 'Add Search Form' : 'Edit Search Form' ), 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'searchforms' ),
479
480 );
481
482 $custom_attributes = array();
483 if ($current_id == 'default' || $current_section == 'editsearchform')
484 {
485 $custom_attributes['disabled'] = 'disabled';
486 }
487
488 $settings[] = array(
489 'title' => __( 'ID', 'propertyhive' ),
490 'id' => 'form_id',
491 'default' => ( (isset($current_id)) ? $current_id : ''),
492 'type' => 'text',
493 'desc_tip' => false,
494 'custom_attributes' => $custom_attributes
495 );
496
497 $settings[] = array(
498 'type' => 'search_form_fields',
499 );
500
501 $settings[] = array( 'type' => 'sectionend', 'id' => 'searchforms');
502
503 return $settings;
504 }
505
506 /**
507 * Output list of search forms
508 *
509 * @access public
510 * @return void
511 */
512 public function search_forms_table() {
513 global $wpdb, $post;
514 ?>
515 <tr valign="top">
516 <th scope="row" class="titledesc">
517 &nbsp;
518 </th>
519 <td class="forminp forminp-button">
520 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=frontend&section=addsearchform' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Search Form', 'propertyhive' )); ?></a>
521 </td>
522 </tr>
523 <tr valign="top">
524 <th scope="row" class="titledesc"><?php esc_html_e( 'Search Forms', 'propertyhive' ) ?></th>
525 <td class="forminp">
526 <table class="ph_portals widefat" cellspacing="0">
527 <thead>
528 <tr>
529 <th class="id"><?php esc_html_e( 'ID', 'propertyhive' ); ?></th>
530 <th class="shortcode"><?php esc_html_e( 'Shortcode', 'propertyhive' ); ?></th>
531 <th class="settings">&nbsp;</th>
532 </tr>
533 </thead>
534 <tbody>
535 <?php
536
537 $current_settings = get_option( 'propertyhive_template_assistant', array() );
538 $search_forms = array();
539 if ($current_settings !== FALSE)
540 {
541 if (isset($current_settings['search_forms']))
542 {
543 $search_forms = $current_settings['search_forms'];
544 }
545 }
546
547 if ( !isset($search_forms['default']) )
548 {
549 $search_forms['default'] = array();
550 }
551
552 if (!empty($search_forms))
553 {
554 foreach ( $search_forms as $id => $search_form )
555 {
556 $edit_url = admin_url( 'admin.php?page=ph-settings&tab=frontend&section=editsearchform&id=' . $id );
557
558 $reset_url = wp_nonce_url(
559 admin_url( 'admin.php?page=ph-settings&tab=frontend&section=search-forms&action=resetsearchform&id=' . $id ),
560 'ph_reset_search_form_' . $id
561 );
562
563 echo '<tr>';
564 echo '<td class="id">' . esc_html( $id ) . '</td>';
565 echo '<td class="shortcode"><pre style="background:#EEE; padding:5px; display:inline">[property_search_form id="' . esc_attr( $id ) . '"]</pre></td>';
566 echo '<td class="settings">
567 <a class="button" href="' . esc_url( $edit_url ) . '">' . esc_html__( 'Edit Fields', 'propertyhive' ) . '</a>
568 <a class="button" href="' . esc_url( $reset_url ) . '">' . esc_html__( 'Reset To Default Fields', 'propertyhive' ) . '</a>';
569
570 if ( $id != 'default' )
571 {
572 $delete_url = wp_nonce_url(
573 admin_url( 'admin.php?page=ph-settings&tab=frontend&section=search-forms&action=deletesearchform&id=' . $id ),
574 'ph_delete_search_form_' . $id
575 );
576
577 echo '
578 <a class="button" href="' . esc_url( $delete_url ) . '" onclick="return confirm(\'Are you sure you wish to delete this search form?\');">' . esc_html__( 'Delete', 'propertyhive' ) . '</a>
579 ';
580 }
581
582 echo '</td>';
583 echo '</tr>';
584 }
585 }
586 else
587 {
588 echo '<tr>';
589 echo '<td align="center" colspan="3">' . esc_html(__( 'No search forms exist', 'propertyhive' )) . '</td>';
590 echo '</tr>';
591 }
592 ?>
593 </tbody>
594 </table>
595 </td>
596 </tr>
597 <tr valign="top">
598 <th scope="row" class="titledesc">
599 &nbsp;
600 </th>
601 <td class="forminp forminp-button">
602 <a href="<?php echo esc_url(admin_url( 'admin.php?page=ph-settings&tab=frontend&section=addsearchform' )); ?>" class="button alignright"><?php echo esc_html(__( 'Add New Search Form', 'propertyhive' )); ?></a>
603 </td>
604 </tr>
605 <?php
606 }
607
608 private function output_search_form_field( $id, $field )
609 {
610 echo '
611 <div class="group" id="' . $id . '">
612 <h3>' . trim( $id, '_' ) . '</h3>
613 <div>';
614 if ( $id == 'department' )
615 {
616 echo '<p><label for="type_'.$id.'">Type:</label> <select name="type[' . $id . ']" id="type_'.$id.'">
617 <option value="radio"' . ( ( !isset($field['type']) || ( isset($field['type']) && $field['type'] == 'radio' ) ) ? ' selected' : '' ) . '>Radio Buttons</option>
618 <option value="select"' . ( ( isset($field['type']) && $field['type'] == 'select' ) ? ' selected' : '' ) . '>Dropdown</option>
619 ' . ( ( isset($field['type']) && $field['type'] != 'select' && $field['type'] != 'radio' ) ? '<option value="' . $field['type'] . '" selected>' . $field['type'] . '</option>' : '' ) . '
620 </select></p>';
621 }
622 else
623 {
624 echo '<input type="hidden" name="type[' . $id . ']" id="type_'.$id.'" value="' . ( ( isset($field['type']) ) ? $field['type'] : '' ) . '">';
625 }
626
627 echo ' <p><label for="show_label_'.$id.'">Show Label:</label> <input type="checkbox" name="show_label[' . $id . ']" id="show_label_'.$id.'" value="1"' . ( ( isset($field['show_label']) && $field['show_label'] === true ) ? ' checked' : '' ) . '></p>
628
629 <p><label for="label_'.$id.'">Label:</label> <input type="text" name="label[' . $id . ']" id="label_'.$id.'" value="' . ( ( isset($field['label']) ) ? $field['label'] : '' ) . '"></p>
630
631 <p><label for="before_'.$id.'">Before:</label> <input type="text" name="before[' . $id . ']" id="before_'.$id.'" value="' . ( ( isset($field['before']) ) ? htmlentities($field['before']) : '' ) . '"></p>
632
633 <p><label for="after_'.$id.'">After:</label> <input type="text" name="after[' . $id . ']" id="after_'.$id.'" value="' . ( ( isset($field['after']) ) ? htmlentities($field['after']) : '' ) . '"></p>';
634
635 if ( isset($field['type']) && in_array($field['type'], array('text', 'email', 'date', 'number', 'password')) )
636 {
637 echo '
638 <p><label for="placeholder_'.$id.'">Placeholder:</label> <input type="text" name="placeholder[' . $id . ']" id="placeholder_'.$id.'" value="' . ( ( isset($field['placeholder']) ) ? htmlentities($field['placeholder']) : '' ) . '"></p>
639 ';
640 }
641
642 if ( isset($field['type']) && in_array($field['type'], array('slider')) )
643 {
644 echo '
645 <p><label for="min_'.$id.'">Min:</label> <input type="number" name="min[' . $id . ']" id="min_'.$id.'" value="' . ( ( isset($field['min']) ) ? htmlentities($field['min']) : '0' ) . '"></p>
646 ';
647
648 echo '
649 <p><label for="max_'.$id.'">Max:</label> <input type="number" name="max[' . $id . ']" id="max_'.$id.'" value="' . ( ( isset($field['max']) ) ? htmlentities($field['max']) : '' ) . '"></p>
650 ';
651
652 echo '
653 <p><label for="step_'.$id.'">Step:</label> <input type="number" name="step[' . $id . ']" id="step_'.$id.'" value="' . ( ( isset($field['step']) ) ? htmlentities($field['step']) : '1' ) . '"></p>
654 ';
655 }
656
657 if ( isset($field['type']) && in_array($field['type'], array('office')) )
658 {
659 echo '
660 <p><label for="blank_option_'.$id.'">Blank Option:</label> <input type="text" name="blank_option[' . $id . ']" id="blank_option_'.$id.'" value="' . ( ( isset($field['blank_option']) ) ? htmlentities($field['blank_option']) : __( 'No Preference', 'propertyhive' ) ) . '"></p>
661 ';
662 }
663
664 if ( taxonomy_exists($id) || ( isset($field['custom_field']) && $field['custom_field'] === true && $field['type'] == 'select' ) )
665 {
666 echo '
667 <p><label for="blank_option_'.$id.'">Blank Option:</label> <input type="text" name="blank_option[' . $id . ']" id="blank_option_'.$id.'" value="' . ( ( isset($field['blank_option']) ) ? htmlentities($field['blank_option']) : __( 'No Preference', 'propertyhive' ) ) . '"></p>
668 ';
669
670 if ( taxonomy_exists($id) && in_array( $id, apply_filters( 'propertyhive_template_assistant_multi_level_taxonomy_fields', array('property_type', 'commercial_property_type', 'location') ) ) )
671 {
672 echo '
673 <p><label for="parent_terms_only_'.$id.'">Top-Level Terms Only:</label> <input type="checkbox" name="parent_terms_only[' . $id . ']" id="parent_terms_only_'.$id.'" value="yes"' . ( ( isset($field['parent_terms_only']) && $field['parent_terms_only'] === true ) ? ' checked' : '' ) . '></p>
674 ';
675
676 echo '
677 <p><label for="hide_empty_'.$id.'">Hide Terms With No Properties Assigned:</label> <input type="checkbox" name="hide_empty[' . $id . ']" id="hide_empty_'.$id.'" value="yes"' . ( ( isset($field['hide_empty']) && $field['hide_empty'] === true ) ? ' checked' : '' ) . '></p>
678 ';
679 }
680
681 if ( taxonomy_exists($id) && in_array( $id, apply_filters( 'propertyhive_template_assistant_dynamic_population_taxonomy_fields', array('location') ) ) )
682 {
683 echo '
684 <p><label for="dynamic_population_'.$id.'">Dynamically Populate Cascading Dropdowns:</label> <input type="checkbox" name="dynamic_population[' . $id . ']" id="dynamic_population_'.$id.'" value="yes"' . ( ( isset($field['dynamic_population']) && $field['dynamic_population'] === true ) ? ' checked' : '' ) . '></p>
685 ';
686 }
687
688 echo '
689 <p><label for="multiselect_'.$id.'">Multi-Select:</label> <input type="checkbox" name="multiselect[' . $id . ']" id="multiselect_'.$id.'" value="yes"' . ( ( isset($field['multiselect']) && $field['multiselect'] === true ) ? ' checked' : '' ) . '></p>
690 ';
691 }
692
693 if ( $id == 'office' )
694 {
695 echo '
696 <p><label for="multiselect_'.$id.'">Multi-Select:</label> <input type="checkbox" name="multiselect[' . $id . ']" id="multiselect_'.$id.'" value="yes"' . ( ( isset($field['multiselect']) && $field['multiselect'] === true ) ? ' checked' : '' ) . '></p>
697 ';
698 }
699
700 if ( isset($field['options']) && !taxonomy_exists($id) && ( !isset($field['custom_field']) || ( isset($field['custom_field']) && $field['custom_field'] === false ) ) )
701 {
702 echo '<p><label for="">Options: ';
703
704 echo '<a href="" class="add-search-form-field-option" id="add_search_form_field_option_' . $id . '">Add Option</a>';
705
706 echo '</label><br>';
707
708 echo '<span class="form-field-options" id="sortable_options_' . $id . '">';
709 $i = 0;
710 foreach ( $field['options'] as $key => $value )
711 {
712 echo '<span style="display:block"><i class="fa fa-reorder" style="cursor:pointer; opacity:0.3"></i> ';
713 echo '<input type="text" name="option_keys[' . $id . '][]" value="' . $key . '">';
714 echo '<input type="text" name="options_values[' . $id . '][]" value="' . $value . '">';
715 echo '</span>';
716
717 ++$i;
718 }
719 echo '</span>';
720
721 echo '</p>';
722 ?>
723 <script>
724 jQuery(document).ready(function($)
725 {
726 $( "#sortable_options_<?php echo $id; ?>" )
727 .sortable({
728 axis: "y",
729 handle: "i",
730 stop: function( event, ui )
731 {
732 // IE doesn't register the blur when sorting
733 // so trigger focusout handlers to remove .ui-state-focus
734 //ui.item.children( "h3" ).triggerHandler( "focusout" );
735
736 // Refresh accordion to handle new order
737 //$( this ).accordion( "refresh" );
738 },
739 update: function( event, ui )
740 {
741 // Update hidden fields
742 var fields_order = $(this).sortable('toArray');
743
744 //$('#active_fields_order').val( fields_order.join("|") );
745 }
746 });
747 });
748 </script>
749 <?php
750 }
751
752 echo '</div>
753 </div>';
754 }
755
756 /**
757 * Output list of search form active/inactive fields
758 *
759 * @access public
760 * @return void
761 */
762 public function search_form_fields() {
763 global $wpdb, $post;
764
765 $current_settings = get_option( 'propertyhive_template_assistant', array() );
766
767 if ( !isset($current_settings['search_forms']) )
768 {
769 $current_settings['search_forms'] = array();
770 }
771 if ( !isset($current_settings['search_forms']['default']) )
772 {
773 $current_settings['search_forms']['default'] = array();
774 }
775
776 $current_id = ( !isset( $_REQUEST['id'] ) ) ? '' : sanitize_title( $_REQUEST['id'] );
777
778 $search_form_details = array();
779
780 if ($current_id != '')
781 {
782 $search_forms = $current_settings['search_forms'];
783
784 if (isset($search_forms[$current_id]))
785 {
786 $search_form_details = $search_forms[$current_id];
787 }
788 else
789 {
790 die('Trying to edit search form which does not exist. Please go back and try again.');
791 }
792 }
793
794 $all_fields = ph_get_search_form_fields();
795 $all_fields['address_keyword'] = array(
796 'type' => 'text',
797 'label' => __( 'Location', 'propertyhive' ),
798 'show_label' => true,
799 'before' => '<div class="control control-address_keyword">'
800 );
801 if ( class_exists('PH_Radial_Search') )
802 {
803 $all_fields['radius'] = array(
804 'type' => 'select',
805 'label' => __( 'Radius', 'propertyhive' ),
806 'show_label' => true,
807 'before' => '<div class="control control-radius">',
808 'options' => array(
809 '' => __( 'This Area Only', 'propertyhive' ),
810 '1' => __( 'Within 1 Mile', 'propertyhive' ),
811 '2' => __( 'Within 2 Miles', 'propertyhive' ),
812 '3' => __( 'Within 3 Miles', 'propertyhive' ),
813 '5' => __( 'Within 5 Miles', 'propertyhive' ),
814 '10' => __( 'Within 10 Miles', 'propertyhive' ),
815 )
816 );
817 }
818 $all_fields['location'] = array(
819 'type' => 'location',
820 'label' => __( 'Location', 'propertyhive' ),
821 'show_label' => true,
822 'before' => '<div class="control control-location">'
823 );
824 $all_fields['parking'] = array(
825 'type' => 'parking',
826 'label' => __( 'Parking', 'propertyhive' ),
827 'show_label' => true,
828 'before' => '<div class="control control-parking residential-only">'
829 );
830 $all_fields['outside_space'] = array(
831 'type' => 'outside_space',
832 'label' => __( 'Outside Space', 'propertyhive' ),
833 'show_label' => true,
834 'before' => '<div class="control control-outside_space residential-only">'
835 );
836 $all_fields['availability'] = array(
837 'type' => 'availability',
838 'label' => __( 'Status', 'propertyhive' ),
839 'show_label' => true,
840 'before' => '<div class="control control-availability">'
841 );
842 $all_fields['marketing_flag'] = array(
843 'type' => 'marketing_flag',
844 'label' => __( 'Marketing Flag', 'propertyhive' ),
845 'show_label' => true,
846 'before' => '<div class="control control-marketing_flag">'
847 );
848 $all_fields['tenure'] = array(
849 'type' => 'tenure',
850 'label' => __( 'Tenure', 'propertyhive' ),
851 'show_label' => true,
852 'before' => '<div class="control control-tenure residential-only">'
853 );
854 $all_fields['commercial_tenure'] = array(
855 'type' => 'commercial_tenure',
856 'label' => __( 'Commercial Tenure', 'propertyhive' ),
857 'show_label' => true,
858 'before' => '<div class="control control-commercial_tenure commercial-only">'
859 );
860 $all_fields['commercial_for_sale_to_rent'] = array(
861 'type' => 'select',
862 'label' => __( 'For Sale / To Rent', 'propertyhive' ),
863 'show_label' => true,
864 'before' => '<div class="control control-commercial_for_sale_to_rent commercial-only">',
865 'options' => array(
866 '' => __( 'No Preference', 'propertyhive' ),
867 'for_sale' => __( 'For Sale', 'propertyhive' ),
868 'to_rent' => __( 'To Rent', 'propertyhive' ),
869 )
870 );
871
872 $prices = array(
873 '' => __( 'No preference', 'propertyhive' ),
874 '100000' => '£100,000',
875 '200000' => '£200,000',
876 '300000' => '£300,000',
877 '400000' => '£400,000',
878 '500000' => '£500,000',
879 '750000' => '£750,000',
880 );
881 $all_fields['commercial_minimum_price'] = array(
882 'type' => 'select',
883 'label' => __( 'Minimum Price', 'propertyhive' ),
884 'show_label' => true,
885 'before' => '<div class="control control-commercial_minimum_price commercial-sales-only">',
886 'options' => $prices
887 );
888 $all_fields['commercial_maximum_price'] = array(
889 'type' => 'select',
890 'label' => __( 'Maximum Price', 'propertyhive' ),
891 'show_label' => true,
892 'before' => '<div class="control control-commercial_maximum_price commercial-sales-only">',
893 'options' => $prices
894 );
895
896 $prices = array(
897 '' => __( 'No preference', 'propertyhive' ),
898 '500' => '£500',
899 '750' => '£750',
900 '1000' => '£1,000',
901 '1500' => '£1,500',
902 '2000' => '£2,000',
903 '3000' => '£3,000',
904 );
905 $all_fields['commercial_minimum_rent'] = array(
906 'type' => 'select',
907 'label' => __( 'Minimum Rent', 'propertyhive' ),
908 'show_label' => true,
909 'before' => '<div class="control control-commercial_minimum_rent commercial-lettings-only">',
910 'options' => $prices
911 );
912 $all_fields['commercial_maximum_rent'] = array(
913 'type' => 'select',
914 'label' => __( 'Maximum Rent', 'propertyhive' ),
915 'show_label' => true,
916 'before' => '<div class="control control-commercial_maximum_rent commercial-lettings-only">',
917 'options' => $prices
918 );
919
920 $all_fields['sale_by'] = array(
921 'type' => 'sale_by',
922 'label' => __( 'Sale By', 'propertyhive' ),
923 'show_label' => true,
924 'before' => '<div class="control control-sale_by">'
925 );
926 $all_fields['furnished'] = array(
927 'type' => 'furnished',
928 'label' => __( 'Furnished', 'propertyhive' ),
929 'show_label' => true,
930 'before' => '<div class="control control-furnished lettings-only">'
931 );
932
933 $price_ranges = array(
934 '' => __( 'No preference', 'propertyhive' ),
935 '100000-200000' => '£100,000 - £200,000',
936 '200000-300000' => '£200,000 - £300,000',
937 '300000-400000' => '£300,000 - £400,000',
938 '400000-500000' => '£400,000 - £500,000',
939 '500000-750000' => '£500,000 - £750,000',
940 '750000-1000000' => '£750,000 - £1,000,000',
941 );
942
943 $all_fields['price_range'] = array(
944 'type' => 'select',
945 'label' => __( 'Price', 'propertyhive' ),
946 'show_label' => true,
947 'before' => '<div class="control control-price-range sales-only">',
948 'options' => $price_ranges
949 );
950
951 $all_fields['price_slider'] = array(
952 'type' => 'slider',
953 'label' => __( 'Price', 'propertyhive' ),
954 'show_label' => true,
955 'before' => '<div class="control control-price-slider sales-only">',
956 'min' => '0',
957 'max' => '1000000',
958 'step' => '10000',
959 );
960
961 $rent_ranges = array(
962 '' => __( 'No preference', 'propertyhive' ),
963 '100-200' => '£100 - £200 PCM',
964 '200-300' => '£200 - £300 PCM',
965 '300-400' => '£300 - £400 PCM',
966 '400-500' => '£400 - £500 PCM',
967 '500-750' => '£500 - £750 PCM',
968 '750-1000' => '£750 - £1,000 PCM',
969 );
970
971 $all_fields['rent_range'] = array(
972 'type' => 'select',
973 'label' => __( 'Rent', 'propertyhive' ),
974 'show_label' => true,
975 'before' => '<div class="control control-rent-range lettings-only">',
976 'options' => $rent_ranges
977 );
978
979 $all_fields['rent_slider'] = array(
980 'type' => 'slider',
981 'label' => __( 'Rent', 'propertyhive' ),
982 'show_label' => true,
983 'before' => '<div class="control control-rent-slider lettings-only">',
984 'min' => '0',
985 'max' => '1000',
986 'step' => '100',
987 );
988
989 $bedrooms = array(
990 '' => __( 'No preference', 'propertyhive' ),
991 '1' => '1',
992 '2' => '2',
993 '3' => '3',
994 '4' => '4',
995 '5' => '5',
996 );
997
998 $all_fields['bedrooms'] = array(
999 'type' => 'select',
1000 'label' => __( 'Bedrooms', 'propertyhive' ),
1001 'show_label' => true,
1002 'before' => '<div class="control control-bedrooms residential-only">',
1003 'options' => $bedrooms
1004 );
1005
1006 $all_fields['maximum_bedrooms'] = array(
1007 'type' => 'select',
1008 'label' => __( 'Max Beds', 'propertyhive' ),
1009 'show_label' => true,
1010 'before' => '<div class="control control-maximum_bedrooms residential-only">',
1011 'options' => $bedrooms
1012 );
1013
1014 $bathrooms = array(
1015 '' => __( 'No preference', 'propertyhive' ),
1016 '1' => '1',
1017 '2' => '2',
1018 '3' => '3',
1019 '4' => '4',
1020 '5' => '5',
1021 );
1022
1023 $all_fields['minimum_bathrooms'] = array(
1024 'type' => 'select',
1025 'label' => __( 'Min Bathrooms', 'propertyhive' ),
1026 'show_label' => true,
1027 'before' => '<div class="control control-minimum_bathrooms residential-only">',
1028 'options' => $bathrooms
1029 );
1030 $all_fields['maximum_bathrooms'] = array(
1031 'type' => 'select',
1032 'label' => __( 'Max Bathrooms', 'propertyhive' ),
1033 'show_label' => true,
1034 'before' => '<div class="control control-maximum_bathrooms residential-only">',
1035 'options' => $bathrooms
1036 );
1037
1038 $reception_rooms = array(
1039 '' => __( 'No preference', 'propertyhive' ),
1040 '1' => '1',
1041 '2' => '2',
1042 '3' => '3',
1043 '4' => '4',
1044 '5' => '5',
1045 );
1046
1047 $all_fields['minimum_reception_rooms'] = array(
1048 'type' => 'select',
1049 'label' => __( 'Min Receptions', 'propertyhive' ),
1050 'show_label' => true,
1051 'before' => '<div class="control control-minimum_reception_rooms residential-only">',
1052 'options' => $reception_rooms
1053 );
1054 $all_fields['maximum_reception_rooms'] = array(
1055 'type' => 'select',
1056 'label' => __( 'Max Receptions', 'propertyhive' ),
1057 'show_label' => true,
1058 'before' => '<div class="control control-maximum_reception_rooms residential-only">',
1059 'options' => $reception_rooms
1060 );
1061
1062 $all_fields['bedrooms_slider'] = array(
1063 'type' => 'slider',
1064 'label' => __( 'Bedrooms', 'propertyhive' ),
1065 'show_label' => true,
1066 'before' => '<div class="control control-bedrooms-slider residential-only">',
1067 'min' => '0',
1068 'max' => '10',
1069 );
1070 $all_fields['available_date_from'] = array(
1071 'type' => 'date',
1072 'label' => __( 'Available From', 'propertyhive' ),
1073 'show_label' => true,
1074 'before' => '<div class="control control-available_date_from lettings-only">'
1075 );
1076
1077 $all_fields['office'] = array(
1078 'type' => 'office',
1079 'label' => __( 'Office', 'propertyhive' ),
1080 'show_label' => true,
1081 'before' => '<div class="control control-office">'
1082 );
1083
1084 $all_fields['keyword'] = array(
1085 'type' => 'text',
1086 'label' => __( 'Keyword', 'propertyhive' ),
1087 'show_label' => true,
1088 'before' => '<div class="control control-keyword">'
1089 );
1090
1091 if ( get_option('propertyhive_features_type') == 'checkbox' )
1092 {
1093 $all_fields['property_feature'] = array(
1094 'type' => 'property_feature',
1095 'label' => __( 'Property Features', 'propertyhive' ),
1096 'show_label' => true,
1097 'before' => '<div class="control control-property_feature">',
1098 'multiselect' => true,
1099 );
1100 }
1101
1102 $all_fields = apply_filters( 'propertyhive_search_form_all_fields', $all_fields );
1103
1104 $currencies = array(
1105 '' => '',
1106 'GBP' => 'GBP',
1107 'EUR' => 'EUR',
1108 'USD' => 'USD',
1109 );
1110
1111 $all_fields['currency'] = array(
1112 'type' => 'select',
1113 'label' => __( 'Currency', 'propertyhive' ),
1114 'show_label' => true,
1115 'before' => '<div class="control control-currency">',
1116 'options' => $currencies
1117 );
1118
1119 $date_added_days = array(
1120 '' => __( 'No preference', 'propertyhive' ),
1121 '1' => 'Last 24 Hours',
1122 '3' => 'Last 3 Days',
1123 '7' => 'Last 7 Days',
1124 '14' => 'Last 14 Days',
1125 );
1126
1127 $all_fields['date_added'] = array(
1128 'type' => 'select',
1129 'show_label' => true,
1130 'label' => __( 'Date Added', 'propertyhive' ),
1131 'options' => $date_added_days
1132 );
1133
1134 $form_controls = ph_get_search_form_fields();
1135 $active_fields = apply_filters( 'propertyhive_search_form_fields_' . $current_id, $form_controls );
1136
1137 // Add any additional fields
1138 if ( isset($current_settings['custom_fields']) && !empty($current_settings['custom_fields']) )
1139 {
1140 foreach ( $current_settings['custom_fields'] as $id => $custom_field )
1141 {
1142 $field_type = 'text';
1143 if ( isset($custom_field['field_type']) )
1144 {
1145 switch ( $custom_field['field_type'] )
1146 {
1147 case 'select':
1148 case 'multiselect':
1149 {
1150 $field_type = 'select';
1151 break;
1152 }
1153 case 'checkbox':
1154 {
1155 $field_type = 'checkbox';
1156 break;
1157 }
1158 }
1159
1160 }
1161
1162 $all_fields[$custom_field['field_name']] = array(
1163 'type' => $field_type,
1164 'label' => $custom_field['field_label'],
1165 'show_label' => true,
1166 'before' => '<div class="control control-' . trim( $custom_field['field_name'], '_' ) . '">',
1167 'custom_field' => true,
1168 );
1169
1170 if ( isset($active_fields[$custom_field['field_name']]) )
1171 {
1172 $active_fields[$custom_field['field_name']]['custom_field'] = true;
1173 }
1174 }
1175 }
1176
1177 $inactive_fields = array();
1178 foreach ( $all_fields as $id => $field )
1179 {
1180 if ( !isset($active_fields[$id]) )
1181 {
1182 if ( isset($search_form_details['inactive_fields'][$id]) && !empty($search_form_details['inactive_fields'][$id]) )
1183 {
1184 $field = array_merge($field, $search_form_details['inactive_fields'][$id]);
1185 }
1186 $inactive_fields[$id] = $field;
1187 }
1188 }
1189 ?>
1190 <tr valign="top">
1191 <th scope="row" class="titledesc"><?php esc_html_e( 'Active Fields', 'propertyhive' ) ?></th>
1192 <td class="forminp">
1193 <div id="sortable1" class="connectedSortable" style="min-height:30px;">
1194 <?php
1195 foreach ( $active_fields as $id => $field )
1196 {
1197 if ( isset( $field['type'] ) && $field['type'] == 'hidden' ) { continue; }
1198
1199 $this->output_search_form_field( $id, $field );
1200 }
1201 ?>
1202 </div>
1203 </td>
1204 </tr>
1205 <tr valign="top">
1206 <th scope="row" class="titledesc"><?php esc_html_e( 'Inactive Fields', 'propertyhive' ) ?></th>
1207 <td class="forminp">
1208 <div id="sortable2" class="connectedSortable" style="min-height:30px;">
1209 <?php
1210 if ( !class_exists('PH_Radial_Search') )
1211 {
1212 // Show radial search with link to buy add on
1213 echo '<div class="group" id="radius-placeholder">
1214 <h3>radius</h3>
1215 <div class="">This field requires the <a href="https://wp-property-hive.com/addons/radial-search/" target="_blank">Radial Search add on</a></div>
1216 </div>';
1217 }
1218 foreach ( $inactive_fields as $id => $field )
1219 {
1220 if ( isset( $field['type'] ) && $field['type'] == 'hidden' ) { continue; }
1221
1222 $this->output_search_form_field( $id, $field );
1223 }
1224 ?>
1225 </div>
1226 </td>
1227 </tr>
1228
1229 <input type="hidden" name="active_fields_order" id="active_fields_order" value="<?php
1230 $field_ids = array();
1231 foreach ( $active_fields as $id => $field )
1232 {
1233 $field_ids[] = $id;
1234 }
1235 echo implode("|", $field_ids);
1236 ?>">
1237 <input type="hidden" name="inactive_fields_order" id="inactive_fields_order" value="<?php
1238 $field_ids = array();
1239 foreach ( $inactive_fields as $id => $field )
1240 {
1241 $field_ids[] = $id;
1242 }
1243 echo implode("|", $field_ids);
1244 ?>">
1245
1246 <script>
1247 jQuery(document).ready(function($)
1248 {
1249 $( "#sortable1" )
1250 .accordion({
1251 collapsible: true,
1252 active: false,
1253 header: "> div > h3",
1254 heightStyle: "content"
1255 })
1256 .sortable({
1257 axis: "y",
1258 handle: "h3",
1259 connectWith: ".connectedSortable",
1260 stop: function( event, ui )
1261 {
1262 // IE doesn't register the blur when sorting
1263 // so trigger focusout handlers to remove .ui-state-focus
1264 ui.item.children( "h3" ).triggerHandler( "focusout" );
1265
1266 // Refresh accordion to handle new order
1267 $( this ).accordion( "refresh" );
1268 },
1269 update: function( event, ui )
1270 {
1271 // Update hidden fields
1272 var fields_order = $(this).sortable('toArray');
1273
1274 fields_order = jQuery.grep(fields_order, function(value) {
1275 return value != 'radius-placeholder';
1276 });
1277
1278 $('#active_fields_order').val( fields_order.join("|") );
1279 }
1280 });
1281
1282 $( "#sortable2" )
1283 .accordion({
1284 collapsible: true,
1285 active: false,
1286 header: "> div > h3",
1287 heightStyle: "content"
1288 })
1289 .sortable({
1290 axis: "y",
1291 handle: "h3",
1292 connectWith: ".connectedSortable",
1293 stop: function( event, ui )
1294 {
1295 // IE doesn't register the blur when sorting
1296 // so trigger focusout handlers to remove .ui-state-focus
1297 ui.item.children( "h3" ).triggerHandler( "focusout" );
1298
1299 // Refresh accordion to handle new order
1300 $( this ).accordion( "refresh" );
1301 },
1302 update: function( event, ui )
1303 {
1304 // Update hidden fields
1305 var fields_order = $(this).sortable('toArray');
1306
1307 fields_order = jQuery.grep(fields_order, function(value) {
1308 return value != 'radius-placeholder';
1309 });
1310
1311 $('#inactive_fields_order').val( fields_order.join("|") );
1312 }
1313 });
1314
1315 // Handle add/remove options
1316 $('body').on('click', '.add-search-form-field-option', function(e)
1317 {
1318 e.preventDefault();
1319
1320 var this_id = $(this).attr('id').replace("add_search_form_field_option_", "");
1321
1322 var clone = $('#sortable_options_' + this_id).children('span').eq(0).clone();
1323 clone.find('input').val('');
1324
1325 clone.appendTo( $('#sortable_options_' + this_id) );
1326
1327 add_remove_option_links();
1328 });
1329
1330 $('body').on('click', '.remove-search-form-field-option', function(e)
1331 {
1332 e.preventDefault();
1333
1334 $(this).parent().remove();
1335
1336 add_remove_option_links();
1337 });
1338
1339 add_remove_option_links();
1340 });
1341
1342 function add_remove_option_links()
1343 {
1344 jQuery('.connectedSortable .group a.remove-search-form-field-option').remove();
1345
1346 jQuery('.connectedSortable .group').each(function()
1347 {
1348 if ( jQuery(this).find('.add-search-form-field-option').length > 0 )
1349 {
1350 console.log(jQuery(this).find('.form-field-options span').length);
1351 if ( jQuery(this).find('.form-field-options span').length > 1 )
1352 {
1353 jQuery(this).find('.form-field-options span').append(' <a href="" class="remove-search-form-field-option">X</a>');
1354 }
1355 }
1356 });
1357 }
1358 </script>
1359 <?php
1360 }
1361
1362 /**
1363 * Get flag settings
1364 *
1365 * @return array Array of settings
1366 */
1367 public function get_flags_settings() {
1368
1369 $current_settings = get_option( 'propertyhive_template_assistant', array() );
1370
1371 $settings = array(
1372
1373 array( 'title' => __( 'Flags', 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'template_assistant_flags_settings' )
1374
1375 );
1376
1377 $settings[] = array(
1378 'title' => __( 'Show Flags On Search Results', 'propertyhive' ),
1379 'id' => 'flags_active',
1380 'type' => 'checkbox',
1381 'default' => ( ( isset($current_settings['flags_active']) && $current_settings['flags_active'] == '1' ) ? 'yes' : ''),
1382 'desc' => 'If checked flags will be shown in search results over the property thumbnail containing the property availability or marketing flag if one selected'
1383 );
1384
1385 $settings[] = array(
1386 'title' => __( 'Show Flags On Property Details', 'propertyhive' ),
1387 'id' => 'flags_active_single',
1388 'type' => 'checkbox',
1389 'default' => ( ( isset($current_settings['flags_active_single']) && $current_settings['flags_active_single'] == '1' ) ? 'yes' : ''),
1390 'desc' => 'If checked flags will be shown over the main image slideshow on the full property details page'
1391 );
1392
1393 $settings[] = array(
1394 'title' => __( 'Position Over Thumbnail', 'propertyhive' ),
1395 'id' => 'flag_position',
1396 'type' => 'select',
1397 'default' => ( isset($current_settings['flag_position']) ? $current_settings['flag_position'] : ''),
1398 'options' => array(
1399 'top:0; left:0;' => 'Top Left',
1400 'top:0; right:0;' => 'Top Right',
1401 'bottom:0; left:0;' => 'Bottom Left',
1402 'bottom:0; right:0;' => 'Bottom Right',
1403 'top:0; left:0; right:0;' => 'Across Top',
1404 'bottom:0; left:0; right:0;' => 'Across Bottom',
1405 )
1406 );
1407
1408 $settings[] = array(
1409 'title' => __( 'Background Colour', 'propertyhive' ),
1410 'id' => 'flag_bg_color',
1411 'type' => 'color',
1412 'default' => ( isset($current_settings['flag_bg_color']) ? $current_settings['flag_bg_color'] : '#000'),
1413 );
1414
1415 $settings[] = array(
1416 'title' => __( 'Text Colour', 'propertyhive' ),
1417 'id' => 'flag_text_color',
1418 'type' => 'color',
1419 'default' => ( isset($current_settings['flag_text_color']) ? $current_settings['flag_text_color'] : '#FFF'),
1420 );
1421
1422 $settings[] = array( 'type' => 'sectionend', 'id' => 'template_assistant_flags_settings');
1423
1424 return $settings;
1425 }
1426
1427 /**
1428 * Output the settings.
1429 */
1430 public function output() {
1431 global $current_section, $hide_save_button;
1432
1433 if ( $current_section )
1434 {
1435 switch ($current_section)
1436 {
1437 case "search-forms": { $hide_save_button = true; $settings = $this->get_search_forms_settings(); break; }
1438 case "addsearchform": { $settings = $this->get_search_form_settings(); break; }
1439 case "editsearchform": { $settings = $this->get_search_form_settings(); break; }
1440 case "flags": { $settings = $this->get_flags_settings(); break; }
1441 default: { die("Unknown setting section"); }
1442 }
1443 }
1444 else
1445 {
1446 $settings = $this->get_settings();
1447 }
1448
1449 PH_Admin_Settings::output_fields( $settings );
1450 }
1451
1452 /**
1453 * Save settings.
1454 */
1455 public function save()
1456 {
1457 global $current_section;
1458
1459 $current_settings = get_option( 'propertyhive_template_assistant', array() );
1460
1461 if ( $current_section != '' )
1462 {
1463 switch ($current_section)
1464 {
1465 case "flags":
1466 {
1467 $propertyhive_template_assistant = array(
1468 'flags_active' => ( ( isset($_POST['flags_active']) ) ? sanitize_text_field($_POST['flags_active']) : '' ),
1469 'flags_active_single' => ( ( isset($_POST['flags_active_single']) ) ? sanitize_text_field($_POST['flags_active_single']) : '' ),
1470 'flag_position' => sanitize_text_field($_POST['flag_position']),
1471 'flag_bg_color' => sanitize_text_field($_POST['flag_bg_color']),
1472 'flag_text_color' => sanitize_text_field($_POST['flag_text_color']),
1473 );
1474
1475 $propertyhive_template_assistant = array_merge($current_settings, $propertyhive_template_assistant);
1476
1477 update_option( 'propertyhive_template_assistant', $propertyhive_template_assistant );
1478 break;
1479 }
1480 case "addsearchform":
1481 case "editsearchform":
1482 {
1483 $current_id = ( !isset( $_REQUEST['id'] ) ) ? '' : sanitize_title( $_REQUEST['id'] );
1484
1485 $existing_search_forms = ( (isset($current_settings['search_forms'])) ? $current_settings['search_forms'] : array() );
1486
1487 if ( $current_section == 'editsearchform' && $current_id != 'default' && !isset($existing_search_forms[$current_id]) )
1488 {
1489 die("Trying to edit a non-existant search form. Please go back and try again");
1490 }
1491
1492 if ( isset($existing_search_forms[$current_id]) )
1493 {
1494 unset($existing_search_forms[$current_id]);
1495 }
1496
1497 $current_id = ( ( isset($_POST['form_id']) && $_POST['form_id'] != '' ) ? str_replace("-", "_", sanitize_title($_POST['form_id'])) : $current_id );
1498 if ($current_section == 'addsearchform' && trim($current_id) == '' )
1499 {
1500 $current_id = 'custom';
1501 }
1502
1503 $active_fields = array();
1504 $inactive_fields = array();
1505
1506 if ( isset($_POST['active_fields_order']) && $_POST['active_fields_order'] != '' )
1507 {
1508 $field_ids = explode("|", sanitize_text_field($_POST['active_fields_order']));
1509 if ( !empty($field_ids) )
1510 {
1511 foreach ( $field_ids as $field_id )
1512 {
1513 $active_fields[$field_id] = array(
1514 'show_label' => ( ( isset($_POST['show_label'][$field_id]) && $_POST['show_label'][$field_id] == '1' ) ? true : false ),
1515 'label' => ( isset($_POST['label'][$field_id]) ? stripslashes($_POST['label'][$field_id]) : '' ),
1516 );
1517
1518 if ( isset($_POST['type'][$field_id]) && $_POST['type'][$field_id] != '' )
1519 {
1520 $active_fields[$field_id]['type'] = stripslashes($_POST['type'][$field_id]);
1521 }
1522 if ( isset($_POST['before'][$field_id]) && $_POST['before'][$field_id] != '' )
1523 {
1524 $active_fields[$field_id]['before'] = stripslashes($_POST['before'][$field_id]);
1525 }
1526 if ( isset($_POST['after'][$field_id]) && $_POST['after'][$field_id] != '' )
1527 {
1528 $active_fields[$field_id]['after'] = stripslashes($_POST['after'][$field_id]);
1529 }
1530 if ( isset($_POST['placeholder'][$field_id]) && $_POST['placeholder'][$field_id] != '' )
1531 {
1532 $active_fields[$field_id]['placeholder'] = stripslashes($_POST['placeholder'][$field_id]);
1533 }
1534 if ( isset($_POST['min'][$field_id]) && $_POST['min'][$field_id] != '' )
1535 {
1536 $active_fields[$field_id]['min'] = stripslashes($_POST['min'][$field_id]);
1537 }
1538 if ( isset($_POST['max'][$field_id]) && $_POST['max'][$field_id] != '' )
1539 {
1540 $active_fields[$field_id]['max'] = stripslashes($_POST['max'][$field_id]);
1541 }
1542 if ( isset($_POST['step'][$field_id]) && $_POST['step'][$field_id] != '' )
1543 {
1544 $active_fields[$field_id]['step'] = stripslashes($_POST['step'][$field_id]);
1545 }
1546 if ( isset($_POST['blank_option'][$field_id]) && $_POST['blank_option'][$field_id] != '' )
1547 {
1548 $active_fields[$field_id]['blank_option'] = stripslashes($_POST['blank_option'][$field_id]);
1549 }
1550 if ( isset($_POST['parent_terms_only'][$field_id]) && $_POST['parent_terms_only'][$field_id] != '' )
1551 {
1552 $active_fields[$field_id]['parent_terms_only'] = true;
1553 }
1554 if ( isset($_POST['dynamic_population'][$field_id]) && $_POST['dynamic_population'][$field_id] != '' )
1555 {
1556 $active_fields[$field_id]['dynamic_population'] = true;
1557 }
1558 if ( isset($_POST['hide_empty'][$field_id]) && $_POST['hide_empty'][$field_id] != '' )
1559 {
1560 $active_fields[$field_id]['hide_empty'] = true;
1561 }
1562 if ( isset($_POST['multiselect'][$field_id]) && $_POST['multiselect'][$field_id] != '' )
1563 {
1564 $active_fields[$field_id]['multiselect'] = true;
1565 }
1566
1567 if ( isset($_POST['option_keys'][$field_id]) && is_array($_POST['option_keys'][$field_id]) && !empty($_POST['option_keys'][$field_id]) )
1568 {
1569 $options = array();
1570 foreach ( $_POST['option_keys'][$field_id] as $i => $key )
1571 {
1572 $options[$key] = $_POST['options_values'][$field_id][$i];
1573 }
1574 $active_fields[$field_id]['options'] = $options;
1575 }
1576 }
1577 }
1578 }
1579
1580 if ( isset($_POST['inactive_fields_order']) && $_POST['inactive_fields_order'] != '' )
1581 {
1582 $field_ids = explode("|", sanitize_text_field($_POST['inactive_fields_order']));
1583 if ( !empty($field_ids) )
1584 {
1585 foreach ( $field_ids as $field_id )
1586 {
1587 $inactive_fields[$field_id] = array(
1588 'show_label' => ( ( isset($_POST['show_label'][$field_id]) && $_POST['show_label'][$field_id] == '1' ) ? true : false ),
1589 'label' => ( isset($_POST['label'][$field_id]) ? stripslashes($_POST['label'][$field_id]) : '' ),
1590 );
1591
1592 if ( isset($_POST['type'][$field_id]) && $_POST['type'][$field_id] != '' )
1593 {
1594 $inactive_fields[$field_id]['type'] = stripslashes($_POST['type'][$field_id]);
1595 }
1596 if ( isset($_POST['before'][$field_id]) && $_POST['before'][$field_id] != '' )
1597 {
1598 $inactive_fields[$field_id]['before'] = stripslashes($_POST['before'][$field_id]);
1599 }
1600 if ( isset($_POST['after'][$field_id]) && $_POST['after'][$field_id] != '' )
1601 {
1602 $inactive_fields[$field_id]['after'] = stripslashes($_POST['after'][$field_id]);
1603 }
1604 if ( isset($_POST['placeholder'][$field_id]) && $_POST['placeholder'][$field_id] != '' )
1605 {
1606 $inactive_fields[$field_id]['placeholder'] = stripslashes($_POST['placeholder'][$field_id]);
1607 }
1608 if ( isset($_POST['blank_option'][$field_id]) && $_POST['blank_option'][$field_id] != '' )
1609 {
1610 $inactive_fields[$field_id]['blank_option'] = stripslashes($_POST['blank_option'][$field_id]);
1611 }
1612 if ( isset($_POST['parent_terms_only'][$field_id]) && $_POST['parent_terms_only'][$field_id] != '' )
1613 {
1614 $inactive_fields[$field_id]['parent_terms_only'] = true;
1615 }
1616 if ( isset($_POST['dynamic_population'][$field_id]) && $_POST['dynamic_population'][$field_id] != '' )
1617 {
1618 $inactive_fields[$field_id]['dynamic_population'] = true;
1619 }
1620 if ( isset($_POST['hide_empty'][$field_id]) && $_POST['hide_empty'][$field_id] != '' )
1621 {
1622 $inactive_fields[$field_id]['hide_empty'] = true;
1623 }
1624 if ( isset($_POST['multiselect'][$field_id]) && $_POST['multiselect'][$field_id] != '' )
1625 {
1626 $inactive_fields[$field_id]['multiselect'] = true;
1627 }
1628
1629 if ( isset($_POST['option_keys'][$field_id]) && is_array($_POST['option_keys'][$field_id]) && !empty($_POST['option_keys'][$field_id]) )
1630 {
1631 $options = array();
1632 foreach ( $_POST['option_keys'][$field_id] as $i => $key )
1633 {
1634 $options[$key] = $_POST['options_values'][$field_id][$i];
1635 }
1636 $inactive_fields[$field_id]['options'] = $options;
1637 }
1638 }
1639 }
1640 }
1641
1642 $existing_search_forms[$current_id] = array(
1643 'active_fields' => $active_fields,
1644 'inactive_fields' => $inactive_fields,
1645 );
1646
1647 $current_settings['search_forms'] = $existing_search_forms;
1648
1649 update_option( 'propertyhive_template_assistant', $current_settings );
1650
1651 break;
1652 }
1653 default: { die("Unknown setting section"); }
1654 }
1655 }
1656 else
1657 {
1658 $search_results_fields = array();
1659 if ( isset($_POST['search_result_fields']) && is_array($_POST['search_result_fields']) )
1660 {
1661 $search_results_fields = $_POST['search_result_fields'];
1662
1663 $new_search_results_fields = array();
1664 foreach ( $search_results_fields as $search_results_field )
1665 {
1666 if ( $search_results_field == 'custom_field' )
1667 {
1668 if ( isset($_POST['search_result_fields_custom_field']) && $_POST['search_result_fields_custom_field'] != '' )
1669 {
1670 $new_search_results_fields[] = ph_clean($_POST['search_result_fields_custom_field']);
1671 }
1672 }
1673 else
1674 {
1675 $new_search_results_fields[] = $search_results_field;
1676 }
1677 }
1678
1679 $search_results_fields = $new_search_results_fields;
1680 }
1681
1682 $propertyhive_template_assistant = array(
1683 'search_result_default_order' => ph_clean($_POST['search_result_default_order']),
1684 'search_result_columns' => (int)$_POST['search_result_columns'],
1685 'search_result_layout' => (int)$_POST['search_result_layout'],
1686 'search_result_fields' => $search_results_fields,
1687 'search_result_image_size' => ( isset($_POST['search_result_image_size']) ? ph_clean($_POST['search_result_image_size']) : 'medium' ),
1688 'search_result_css' => wp_unslash($_POST['search_result_css']),
1689 'search_result_css_all_pages' => isset($_POST['search_result_css_all_pages']) ? 'yes' : '',
1690 );
1691
1692 $propertyhive_template_assistant = array_merge($current_settings, $propertyhive_template_assistant);
1693
1694 update_option( 'propertyhive_template_assistant', $propertyhive_template_assistant );
1695 }
1696 }
1697 }
1698
1699 endif;
1700
1701 return new PH_Settings_Frontend();