PluginProbe
Property Hive / 2.2.4
Property Hive v2.2.4
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.4, at includes/admin/settings/class-ph-settings-frontend.php

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