Function Reference: geodir_advance_search_listing_page_title

Summary

This function has not been documented yet.

Filters

‘geodir_advance_search_filter_title’ [Line: 547]

Source File

geodir_advance_search_listing_page_title() is located in geodir_advance_search_filters/geodirectory_advance_search_hooks_actions.php [Line: 317]

Source Code

function geodir_advance_search_listing_page_title($list_title) {
	if (!geodir_is_page('search')) {
		return $list_title;
	}
	$gd_post_type = geodir_get_current_posttype();
	$post_type_info = get_post_type_object($gd_post_type);
		
	if(trim(get_search_query())=='') {
		$list_title = __('Search', GEODIRECTORY_TEXTDOMAIN).' '.__(ucfirst($post_type_info->labels->name), GEODIRECTORY_TEXTDOMAIN ).__(' :',GEODIRECTORY_TEXTDOMAIN);
	}
	
	if (!get_option('geodir_search_display_searched_params')) {
		return $list_title;
	}
	
	$custom_fields = geodir_advance_search_get_advance_search_fields($gd_post_type);
	$search_title = array();
	if (isset($_REQUEST['snear']) && $_REQUEST['snear'] != '') {
		$search_title[] = '<label class="gd-adv-search-label gd-adv-search-near">'.esc_attr($_REQUEST['snear']).'</label>';
	}
	if (!empty($custom_fields)) {
		foreach($custom_fields as $custom_field) {
			$site_htmlvar_name = $custom_field->site_htmlvar_name;
			$field_site_name = $custom_field->field_site_name;
			$field_site_type = $custom_field->field_site_type;
			$front_search_title = $custom_field->front_search_title!='' ? $custom_field->front_search_title : $field_site_name;
			$field_input_type = $custom_field->field_input_type;
			$search_condition = $custom_field->search_condition;
			$field_data_type = $custom_field->field_data_type;
									
			switch($field_input_type) {
				case 'RANGE': {
					switch($search_condition) {
						case 'SINGLE': {
							if (isset($_REQUEST['s'.$site_htmlvar_name]) && $_REQUEST['s'.$site_htmlvar_name] != '') {
								$extra_attrs = 'data-name="s' . $site_htmlvar_name . '"';
								$search_title[] = '<label class="gd-adv-search-label gd-adv-search-range gd-adv-search-'.$site_htmlvar_name.'" ' . $extra_attrs . '>'.esc_attr($_REQUEST['s' . $site_htmlvar_name]).'</label>';
							}
						}
						break;
						case 'FROM': {
							$minvalue = isset($_REQUEST['smin'.$site_htmlvar_name]) && !empty($_REQUEST['smin'.$site_htmlvar_name]) ? esc_attr($_REQUEST['smin'.$site_htmlvar_name]) : '';
							$maxvalue = isset($_REQUEST['smax'.$site_htmlvar_name]) && !empty($_REQUEST['smax'.$site_htmlvar_name]) ? esc_attr($_REQUEST['smax'.$site_htmlvar_name]) : '';
							$this_search = '';
							if ($minvalue != '' && $maxvalue != '') {
								$this_search = $minvalue.' - '.$maxvalue;
							} else if ($minvalue != '' && $maxvalue == '') {
								$this_search = __('From:', GEODIRADVANCESEARCH_TEXTDOMAIN).' '.$minvalue;
							} else if ($minvalue == '' && $maxvalue != '') {
								$this_search = __('To:', GEODIRADVANCESEARCH_TEXTDOMAIN).' '.$maxvalue;
							}
							
							if ($this_search != '') {
								$extra_attrs = 'data-name="smin' . $site_htmlvar_name . '" data-names="smax' . $site_htmlvar_name . '"';
								$search_title[] = '<label class="gd-adv-search-label gd-adv-search-range gd-adv-search-'.$site_htmlvar_name.'" ' . $extra_attrs . '>'.esc_attr($this_search).'</label>';
							}
						}		
						break;
						case 'RADIO': {
							if (isset($_REQUEST['s'.$site_htmlvar_name]) && $_REQUEST['s'.$site_htmlvar_name] != '') {
								$uom = get_option('geodir_search_dist_1');	
								$extra_attrs = 'data-name="s' . $site_htmlvar_name . '"';
								$search_title[] = '<label class="gd-adv-search-label gd-adv-search-range gd-adv-search-'.$site_htmlvar_name.'" ' . $extra_attrs . '>'.__('Within', GEODIRADVANCESEARCH_TEXTDOMAIN).' '.(int)esc_attr($_REQUEST['s'.$site_htmlvar_name]).' '.__($uom, GEODIRECTORY_TEXTDOMAIN).'</label>';
							}
						}
						break;
						default : {
							if (isset($_REQUEST['s'.$site_htmlvar_name]) && $_REQUEST['s'.$site_htmlvar_name] != '') {
								$serchlist =  explode("-", esc_attr($_REQUEST['s'.$site_htmlvar_name]));
								if (!empty($serchlist)) {
									$first_value = $serchlist[0];
									$second_value = isset($serchlist[1]) ? trim($serchlist[1], ' ') : '';
									$rest = substr($second_value, 0, 4); 
									
									$this_search = '';
									if ($rest == 'Less') {
										$this_search = __('To:', GEODIRADVANCESEARCH_TEXTDOMAIN).' '.$first_value;
									} else if ($rest == 'More') {
										$this_search = __('From:', GEODIRADVANCESEARCH_TEXTDOMAIN).' '.$first_value;
									} else if ($second_value != '') {
										$this_search = $first_value.' - '.$second_value;
									}
									
									if ($this_search != '') {
										$extra_attrs = 'data-name="s' . $site_htmlvar_name . '"';
										$search_title[] = '<label class="gd-adv-search-label gd-adv-search-range gd-adv-search-'.$site_htmlvar_name.'" ' . $extra_attrs . '>'.esc_attr($this_search).'</label>';
									}
								}
							}
						}
						break;
					}
				}
				break;
				case 'DATE': {
					$search_date = '';
					$single = '';
					$this_search = '';
					$value = isset($_REQUEST['s'.$site_htmlvar_name]) && !empty($_REQUEST['s'.$site_htmlvar_name]) ? esc_attr($_REQUEST['s'.$site_htmlvar_name]) : '';
					
					$extra_attrs = 'data-name="s' . $site_htmlvar_name . '"';
					
					if($value) {
						$minvalue = $value;
						$maxvalue = '';
						$single = '1';
					} else {
						$minvalue = isset($_REQUEST['smin'.$site_htmlvar_name]) && !empty($_REQUEST['smin'.$site_htmlvar_name]) ? esc_attr($_REQUEST['smin'.$site_htmlvar_name]) : '';
						$maxvalue = isset($_REQUEST['smax'.$site_htmlvar_name]) && !empty($_REQUEST['smax'.$site_htmlvar_name]) ? esc_attr($_REQUEST['smax'.$site_htmlvar_name]) : '';
						$extra_attrs = 'data-name="smin' . $site_htmlvar_name . '" data-names="smax' . $site_htmlvar_name . '"';
					}
				
					if ($site_htmlvar_name == 'event') {
						$event_start = isset($_REQUEST['event_start']) && !empty($_REQUEST['event_start']) ? esc_attr($_REQUEST['event_start']) : '';
						$event_end = isset($_REQUEST['event_end']) && !empty($_REQUEST['event_end']) ? esc_attr($_REQUEST['event_end']) : '';
						
						$extra_attrs = 'data-name="event_start" data-names="event_end"';
						
						if ($event_start != '' && $event_end == '') {
							$this_search = __('From:', GEODIRADVANCESEARCH_TEXTDOMAIN).' '.$event_start;
						} else if ($event_start == '' && $event_end != '') {
							$this_search = __('To:', GEODIRADVANCESEARCH_TEXTDOMAIN).' '.$event_end;
						} else if ($event_start != '' && $event_end != '') {
							$this_search = $event_start.' - '.$event_end;
						}
						
						if ($this_search != '') {
							$search_title[] = '<label class="gd-adv-search-label gd-adv-search-date gd-adv-search-'.$site_htmlvar_name.'" ' . $extra_attrs . '>'.esc_attr($this_search).'</label>';
						}
					} else if( $field_data_type == 'DATE' || $field_data_type == 'TIME' ) {
						$start_date = date( 'Y-m-d', strtotime( $minvalue ) );
						$start_end = date( 'Y-m-d', strtotime( $maxvalue ) );
						
						if( $single == '1' ) {
							$search_title[] = '<label class="gd-adv-search-label gd-adv-search-date gd-adv-search-'.$site_htmlvar_name.'" ' . $extra_attrs . '>'.esc_attr($minvalue).'</label>';
						} else {
							$this_search = '';
							if ($minvalue != '' && $maxvalue == '') {
								$this_search = __('From:', GEODIRADVANCESEARCH_TEXTDOMAIN).' '.$minvalue;
							} else if ($minvalue == '' && $maxvalue != '') {
								$this_search = __('To:', GEODIRADVANCESEARCH_TEXTDOMAIN).' '.$maxvalue;
							} else if ($minvalue != '' && $maxvalue != '') {
								$this_search = $minvalue.' - '.$maxvalue;
							}
							
							if ($this_search != '') {
								$search_title[] = '<label class="gd-adv-search-label gd-adv-search-date gd-adv-search-'.$site_htmlvar_name.'" ' . $extra_attrs . '>'.esc_attr($this_search).'</label>';
							}
						}		
					}
				}
				break;
				default: {
					if (isset($_REQUEST['s'.$site_htmlvar_name]) && ((is_array($_REQUEST['s'.$site_htmlvar_name]) && !empty($_REQUEST['s'.$site_htmlvar_name])) || (!is_array($_REQUEST['s'.$site_htmlvar_name]) && $_REQUEST['s'.$site_htmlvar_name]!=''))) {
						$value = esc_attr($_REQUEST['s'.$site_htmlvar_name]);
												
						if (is_array($_REQUEST['s'.$site_htmlvar_name])) {							
							$extra_attrs = 'data-name="s' . $site_htmlvar_name . '[]"';
							$values = array_map( 'esc_attr',$_REQUEST['s'.$site_htmlvar_name]);
							$value = '';
							if ($site_htmlvar_name==$gd_post_type.'category') {
								$value = array();
								foreach ($values as $value_id) {
									$value_term = get_term($value_id, $site_htmlvar_name);
									if (!empty($value_term) && isset($value_term->name)) {
										$value[] = $value_term->name;
									}
								}
								$value = !empty($value) ? implode(', ', $value) : '';
							} else {
								$field_option_values = geodir_advance_search_field_option_values($gd_post_type, $site_htmlvar_name);
								$field_option_values = geodir_string_values_to_options( $field_option_values );
								if (!empty($field_option_values)) {
									$value = array();
									foreach ($field_option_values as $option_value) {
										$option_label = isset( $option_value['label'] ) ? $option_value['label'] : '';
										$option_val = isset( $option_value['value'] ) ? $option_value['value'] : $option_label;

										if ($option_label != '' && $option_val!='' && in_array($option_val, $_REQUEST['s'.$site_htmlvar_name])) {
											$value[] = __(ucfirst($option_label), GEODIRECTORY_TEXTDOMAIN);
										}
									}
									$value = !empty($value) ? implode(', ', $value) : '';
								} else {
									$value = implode(', ', $values);
								}
							}
						} else {
							$extra_attrs = 'data-name="s' . $site_htmlvar_name . '"';
							
							if ($site_htmlvar_name==$gd_post_type.'category') {
								$value = '';
								$value_term = get_term(esc_attr($_REQUEST['s'.$site_htmlvar_name]), $site_htmlvar_name);
								if (!empty($value_term) && isset($value_term->name)) {
									$value = $value_term->name;
								}
							} else {
								$field_option_values = geodir_advance_search_field_option_values($gd_post_type, $site_htmlvar_name);
								$field_option_values = geodir_string_values_to_options( $field_option_values );
								if (!empty($field_option_values)) {
									$value = array();
									foreach ($field_option_values as $option_value) {
										$option_label = isset( $option_value['label'] ) ? $option_value['label'] : '';
										$option_val = isset( $option_value['value'] ) ? $option_value['value'] : $option_label;

										if ($option_label != '' && $option_val!='' && $option_val == $_REQUEST['s'.$site_htmlvar_name]) {
											$value[] = __(ucfirst($option_label), GEODIRECTORY_TEXTDOMAIN);
										}
									}
									$value = !empty($value) ? implode(', ', $value) : '';
								}
								
								if ($field_site_type=='checkbox' && (int)$_REQUEST['s'.$site_htmlvar_name]==1) {
									$value = __($front_search_title, GEODIRADVANCESEARCH_TEXTDOMAIN);
								}
							}
						}
						
						if ($value!='') {
							$search_title[] = '<label class="gd-adv-search-label gd-adv-search-default gd-adv-search-'.$site_htmlvar_name.'" ' . $extra_attrs . '>'.esc_attr($value).'</label>';
						}
					}
				}
				break;
			}
		}
	}
	
	if (!empty($search_title)) {
		$search_title = '<div class="gd-adv-search-labels">'.implode($search_title, '').'</div>';
		$search_title = apply_filters('geodir_advance_search_filter_title', $search_title);
		$list_title .= $search_title;
	}

	return $list_title;
}