',
'options' => $currencies
);
$date_added_days = array(
'' => __( 'No preference', 'propertyhive' ),
'1' => 'Last 24 Hours',
'3' => 'Last 3 Days',
'7' => 'Last 7 Days',
'14' => 'Last 14 Days',
);
$all_fields['date_added'] = array(
'type' => 'select',
'show_label' => true,
'label' => __( 'Date Added', 'propertyhive' ),
'options' => $date_added_days
);
$form_controls = ph_get_search_form_fields();
$active_fields = apply_filters( 'propertyhive_search_form_fields_' . $current_id, $form_controls );
// Add any additional fields
if ( isset($current_settings['custom_fields']) && !empty($current_settings['custom_fields']) )
{
foreach ( $current_settings['custom_fields'] as $id => $custom_field )
{
$field_type = 'text';
if ( isset($custom_field['field_type']) )
{
switch ( $custom_field['field_type'] )
{
case 'select':
case 'multiselect':
{
$field_type = 'select';
break;
}
case 'checkbox':
{
$field_type = 'checkbox';
break;
}
}
}
$all_fields[$custom_field['field_name']] = array(
'type' => $field_type,
'label' => $custom_field['field_label'],
'show_label' => true,
'before' => '
',
'custom_field' => true,
);
if ( isset($active_fields[$custom_field['field_name']]) )
{
$active_fields[$custom_field['field_name']]['custom_field'] = true;
}
}
}
$inactive_fields = array();
foreach ( $all_fields as $id => $field )
{
if ( !isset($active_fields[$id]) )
{
if ( isset($search_form_details['inactive_fields'][$id]) && !empty($search_form_details['inactive_fields'][$id]) )
{
$field = array_merge($field, $search_form_details['inactive_fields'][$id]);
}
$inactive_fields[$id] = $field;
}
}
?>
|
$field )
{
if ( isset( $field['type'] ) && $field['type'] == 'hidden' ) { continue; }
$this->output_search_form_field( $id, $field );
}
?>
|
|
';
}
foreach ( $inactive_fields as $id => $field )
{
if ( isset( $field['type'] ) && $field['type'] == 'hidden' ) { continue; }
$this->output_search_form_field( $id, $field );
}
?>
|
">
">
__( 'Flags', 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'template_assistant_flags_settings' )
);
$settings[] = array(
'title' => __( 'Show Flags On Search Results', 'propertyhive' ),
'id' => 'flags_active',
'type' => 'checkbox',
'default' => ( ( isset($current_settings['flags_active']) && $current_settings['flags_active'] == '1' ) ? 'yes' : ''),
'desc' => 'If checked flags will be shown in search results over the property thumbnail containing the property availability or marketing flag if one selected'
);
$settings[] = array(
'title' => __( 'Show Flags On Property Details', 'propertyhive' ),
'id' => 'flags_active_single',
'type' => 'checkbox',
'default' => ( ( isset($current_settings['flags_active_single']) && $current_settings['flags_active_single'] == '1' ) ? 'yes' : ''),
'desc' => 'If checked flags will be shown over the main image slideshow on the full property details page'
);
$settings[] = array(
'title' => __( 'Position Over Thumbnail', 'propertyhive' ),
'id' => 'flag_position',
'type' => 'select',
'default' => ( isset($current_settings['flag_position']) ? $current_settings['flag_position'] : ''),
'options' => array(
'top:0; left:0;' => 'Top Left',
'top:0; right:0;' => 'Top Right',
'bottom:0; left:0;' => 'Bottom Left',
'bottom:0; right:0;' => 'Bottom Right',
'top:0; left:0; right:0;' => 'Across Top',
'bottom:0; left:0; right:0;' => 'Across Bottom',
)
);
$settings[] = array(
'title' => __( 'Background Colour', 'propertyhive' ),
'id' => 'flag_bg_color',
'type' => 'color',
'default' => ( isset($current_settings['flag_bg_color']) ? $current_settings['flag_bg_color'] : '#000'),
);
$settings[] = array(
'title' => __( 'Text Colour', 'propertyhive' ),
'id' => 'flag_text_color',
'type' => 'color',
'default' => ( isset($current_settings['flag_text_color']) ? $current_settings['flag_text_color'] : '#FFF'),
);
$settings[] = array( 'type' => 'sectionend', 'id' => 'template_assistant_flags_settings');
return $settings;
}
/**
* Output the settings.
*/
public function output() {
global $current_section, $hide_save_button;
if ( $current_section )
{
switch ($current_section)
{
case "search-forms": { $hide_save_button = true; $settings = $this->get_search_forms_settings(); break; }
case "addsearchform": { $settings = $this->get_search_form_settings(); break; }
case "editsearchform": { $settings = $this->get_search_form_settings(); break; }
case "flags": { $settings = $this->get_flags_settings(); break; }
default: { die("Unknown setting section"); }
}
}
else
{
$settings = $this->get_settings();
}
PH_Admin_Settings::output_fields( $settings );
}
/**
* Save settings.
*/
public function save()
{
global $current_section;
$current_settings = get_option( 'propertyhive_template_assistant', array() );
if ( $current_section != '' )
{
switch ($current_section)
{
case "flags":
{
$propertyhive_template_assistant = array(
'flags_active' => ( ( isset($_POST['flags_active']) ) ? sanitize_text_field($_POST['flags_active']) : '' ),
'flags_active_single' => ( ( isset($_POST['flags_active_single']) ) ? sanitize_text_field($_POST['flags_active_single']) : '' ),
'flag_position' => sanitize_text_field($_POST['flag_position']),
'flag_bg_color' => sanitize_text_field($_POST['flag_bg_color']),
'flag_text_color' => sanitize_text_field($_POST['flag_text_color']),
);
$propertyhive_template_assistant = array_merge($current_settings, $propertyhive_template_assistant);
update_option( 'propertyhive_template_assistant', $propertyhive_template_assistant );
break;
}
case "addsearchform":
case "editsearchform":
{
$current_id = ( !isset( $_REQUEST['id'] ) ) ? '' : sanitize_title( $_REQUEST['id'] );
$existing_search_forms = ( (isset($current_settings['search_forms'])) ? $current_settings['search_forms'] : array() );
if ( $current_section == 'editsearchform' && $current_id != 'default' && !isset($existing_search_forms[$current_id]) )
{
die("Trying to edit a non-existant search form. Please go back and try again");
}
if ( isset($existing_search_forms[$current_id]) )
{
unset($existing_search_forms[$current_id]);
}
$current_id = ( ( isset($_POST['form_id']) && $_POST['form_id'] != '' ) ? str_replace("-", "_", sanitize_title($_POST['form_id'])) : $current_id );
if ($current_section == 'addsearchform' && trim($current_id) == '' )
{
$current_id = 'custom';
}
$active_fields = array();
$inactive_fields = array();
if ( isset($_POST['active_fields_order']) && $_POST['active_fields_order'] != '' )
{
$field_ids = explode("|", sanitize_text_field($_POST['active_fields_order']));
if ( !empty($field_ids) )
{
foreach ( $field_ids as $field_id )
{
$active_fields[$field_id] = array(
'show_label' => ( ( isset($_POST['show_label'][$field_id]) && $_POST['show_label'][$field_id] == '1' ) ? true : false ),
'label' => ( isset($_POST['label'][$field_id]) ? stripslashes($_POST['label'][$field_id]) : '' ),
);
if ( isset($_POST['type'][$field_id]) && $_POST['type'][$field_id] != '' )
{
$active_fields[$field_id]['type'] = stripslashes($_POST['type'][$field_id]);
}
if ( isset($_POST['before'][$field_id]) && $_POST['before'][$field_id] != '' )
{
$active_fields[$field_id]['before'] = stripslashes($_POST['before'][$field_id]);
}
if ( isset($_POST['after'][$field_id]) && $_POST['after'][$field_id] != '' )
{
$active_fields[$field_id]['after'] = stripslashes($_POST['after'][$field_id]);
}
if ( isset($_POST['placeholder'][$field_id]) && $_POST['placeholder'][$field_id] != '' )
{
$active_fields[$field_id]['placeholder'] = stripslashes($_POST['placeholder'][$field_id]);
}
if ( isset($_POST['min'][$field_id]) && $_POST['min'][$field_id] != '' )
{
$active_fields[$field_id]['min'] = stripslashes($_POST['min'][$field_id]);
}
if ( isset($_POST['max'][$field_id]) && $_POST['max'][$field_id] != '' )
{
$active_fields[$field_id]['max'] = stripslashes($_POST['max'][$field_id]);
}
if ( isset($_POST['step'][$field_id]) && $_POST['step'][$field_id] != '' )
{
$active_fields[$field_id]['step'] = stripslashes($_POST['step'][$field_id]);
}
if ( isset($_POST['blank_option'][$field_id]) && $_POST['blank_option'][$field_id] != '' )
{
$active_fields[$field_id]['blank_option'] = stripslashes($_POST['blank_option'][$field_id]);
}
if ( isset($_POST['parent_terms_only'][$field_id]) && $_POST['parent_terms_only'][$field_id] != '' )
{
$active_fields[$field_id]['parent_terms_only'] = true;
}
if ( isset($_POST['dynamic_population'][$field_id]) && $_POST['dynamic_population'][$field_id] != '' )
{
$active_fields[$field_id]['dynamic_population'] = true;
}
if ( isset($_POST['hide_empty'][$field_id]) && $_POST['hide_empty'][$field_id] != '' )
{
$active_fields[$field_id]['hide_empty'] = true;
}
if ( isset($_POST['multiselect'][$field_id]) && $_POST['multiselect'][$field_id] != '' )
{
$active_fields[$field_id]['multiselect'] = true;
}
if ( isset($_POST['option_keys'][$field_id]) && is_array($_POST['option_keys'][$field_id]) && !empty($_POST['option_keys'][$field_id]) )
{
$options = array();
foreach ( $_POST['option_keys'][$field_id] as $i => $key )
{
$options[$key] = $_POST['options_values'][$field_id][$i];
}
$active_fields[$field_id]['options'] = $options;
}
}
}
}
if ( isset($_POST['inactive_fields_order']) && $_POST['inactive_fields_order'] != '' )
{
$field_ids = explode("|", sanitize_text_field($_POST['inactive_fields_order']));
if ( !empty($field_ids) )
{
foreach ( $field_ids as $field_id )
{
$inactive_fields[$field_id] = array(
'show_label' => ( ( isset($_POST['show_label'][$field_id]) && $_POST['show_label'][$field_id] == '1' ) ? true : false ),
'label' => ( isset($_POST['label'][$field_id]) ? stripslashes($_POST['label'][$field_id]) : '' ),
);
if ( isset($_POST['type'][$field_id]) && $_POST['type'][$field_id] != '' )
{
$inactive_fields[$field_id]['type'] = stripslashes($_POST['type'][$field_id]);
}
if ( isset($_POST['before'][$field_id]) && $_POST['before'][$field_id] != '' )
{
$inactive_fields[$field_id]['before'] = stripslashes($_POST['before'][$field_id]);
}
if ( isset($_POST['after'][$field_id]) && $_POST['after'][$field_id] != '' )
{
$inactive_fields[$field_id]['after'] = stripslashes($_POST['after'][$field_id]);
}
if ( isset($_POST['placeholder'][$field_id]) && $_POST['placeholder'][$field_id] != '' )
{
$inactive_fields[$field_id]['placeholder'] = stripslashes($_POST['placeholder'][$field_id]);
}
if ( isset($_POST['blank_option'][$field_id]) && $_POST['blank_option'][$field_id] != '' )
{
$inactive_fields[$field_id]['blank_option'] = stripslashes($_POST['blank_option'][$field_id]);
}
if ( isset($_POST['parent_terms_only'][$field_id]) && $_POST['parent_terms_only'][$field_id] != '' )
{
$inactive_fields[$field_id]['parent_terms_only'] = true;
}
if ( isset($_POST['dynamic_population'][$field_id]) && $_POST['dynamic_population'][$field_id] != '' )
{
$inactive_fields[$field_id]['dynamic_population'] = true;
}
if ( isset($_POST['hide_empty'][$field_id]) && $_POST['hide_empty'][$field_id] != '' )
{
$inactive_fields[$field_id]['hide_empty'] = true;
}
if ( isset($_POST['multiselect'][$field_id]) && $_POST['multiselect'][$field_id] != '' )
{
$inactive_fields[$field_id]['multiselect'] = true;
}
if ( isset($_POST['option_keys'][$field_id]) && is_array($_POST['option_keys'][$field_id]) && !empty($_POST['option_keys'][$field_id]) )
{
$options = array();
foreach ( $_POST['option_keys'][$field_id] as $i => $key )
{
$options[$key] = $_POST['options_values'][$field_id][$i];
}
$inactive_fields[$field_id]['options'] = $options;
}
}
}
}
$existing_search_forms[$current_id] = array(
'active_fields' => $active_fields,
'inactive_fields' => $inactive_fields,
);
$current_settings['search_forms'] = $existing_search_forms;
update_option( 'propertyhive_template_assistant', $current_settings );
break;
}
default: { die("Unknown setting section"); }
}
}
else
{
$search_results_fields = array();
if ( isset($_POST['search_result_fields']) && is_array($_POST['search_result_fields']) )
{
$search_results_fields = $_POST['search_result_fields'];
$new_search_results_fields = array();
foreach ( $search_results_fields as $search_results_field )
{
if ( $search_results_field == 'custom_field' )
{
if ( isset($_POST['search_result_fields_custom_field']) && $_POST['search_result_fields_custom_field'] != '' )
{
$new_search_results_fields[] = ph_clean($_POST['search_result_fields_custom_field']);
}
}
else
{
$new_search_results_fields[] = $search_results_field;
}
}
$search_results_fields = $new_search_results_fields;
}
$propertyhive_template_assistant = array(
'search_result_default_order' => ph_clean($_POST['search_result_default_order']),
'search_result_columns' => (int)$_POST['search_result_columns'],
'search_result_layout' => (int)$_POST['search_result_layout'],
'search_result_fields' => $search_results_fields,
'search_result_image_size' => ( isset($_POST['search_result_image_size']) ? ph_clean($_POST['search_result_image_size']) : 'medium' ),
'search_result_css' => wp_unslash($_POST['search_result_css']),
'search_result_css_all_pages' => isset($_POST['search_result_css_all_pages']) ? 'yes' : '',
);
$propertyhive_template_assistant = array_merge($current_settings, $propertyhive_template_assistant);
update_option( 'propertyhive_template_assistant', $propertyhive_template_assistant );
}
}
}
endif;
return new PH_Settings_Frontend();