function collab_tag_names($idx, $field = null) { $search_fields = search_fields($idx); $tags = array(); $fieldTags = array_map(function ($search_field) use(&$tags) { $tags[$search_field['form_field']] = $search_field['name']; }, $search_fields); if ($field) { return array('field' => $field, 'title' => $tags[$field]); } else { return array_filter($tags); } }
$maxOptions = isset($_POST['max_options']) && is_int($_POST['max_options']) ? $_POST['max_options'] : $_POST['max_options'] !== 'false' ? 30 : false; // If a field has this many or less results, it will display all of them instead of a weighted amount. $minOptions = isset($_POST['min_options']) && is_int($_POST['min_options']) ? $_POST['min_options'] : $_POST['min_options'] !== 'false' ? 3 : false; // Include IDX Configuration include_once $_SERVER['DOCUMENT_ROOT'] . '/idx/common.inc.php'; $json = array(); $errors = array(); $success = array(); $universal_fields = array('search_mls', 'search_city', 'search_zip', 'search_county', 'search_area', 'search_subdivision', 'search_address', 'school_district', 'school_elementary', 'school_middle', 'school_high'); $idx = Util_IDX::getIDX(); $db_idx = Util_IDX::getDatabase(); $optionSets = array(); $optionCounts = array(); if (!empty($_POST['q'])) { $html = ''; $search_fields = search_fields($idx); foreach ($universal_fields as $field) { $search_field = $search_fields[$field]; // obey client city list, use IDX Panel to fetch city options if ($field == 'search_city') { $cityPanel = new IDX_Panel_City(); $cityOptions = $cityPanel->getOptions(); $options = array_filter($cityOptions, function ($option) { if (stripos($option['value'], $_POST['q']) === 0) { return $option; } return false; }); if ($options) { $optionSets[] = array('options' => $options, 'count' => count($options), 'settings' => array('field' => $field, 'name' => $search_field['name'])); $optionCounts[] = count($options);
$tags[] = array('field' => $field . '[]', 'title' => $tagNames[$field] . ': ' . formatOption($field, $val), 'value' => $val); } } else { $tags[] = array('field' => $field, 'title' => $tagNames[$field] . ': ' . formatOption($field, $value), 'value' => $value); } } if (!empty($_REQUEST['map']['polygon'])) { $tags[] = array('field' => 'map_polygon', 'title' => 'Custom Polygon', 'value' => htmlspecialchars(str_replace('"', "'", $_REQUEST['map']['polygon']))); } if (!empty($_REQUEST['map']['radius'])) { $tags[] = array('field' => 'map_radius', 'title' => 'Custom Radius', 'value' => htmlspecialchars(str_replace('"', "'", $_REQUEST['map']['radius']))); } // Searchable IDX Fields $searchable = array_merge(array_map(function ($field) { return $field['form_field']; }, search_fields($idx)), array('map', 'order', 'sort', 'view', 'lead_id', 'create_search', 'edit_search', 'save_prompt', 'search_title', 'search_location', 'frequency', 'saved_search_id', 'suggested', 'auto_save')); // Current Search Criteria $criteria = array(); array_walk($_REQUEST, function ($v, $k) use(&$criteria, $searchable) { if (!empty($v) && in_array($k, $searchable)) { $criteria[$k] = $v; } }); // Extra Search Criteria $criteria = array_merge($criteria, array('feed' => $idx->getLink(), 'save_prompt' => $idx->buildSearchTitle($_REQUEST), 'search_title' => $idx->buildSearchTitle($_REQUEST))); $this->config('criteria', $criteria); $_REQUEST = $oldRequest; function formatOption($field, $value) { if (is_numeric($value)) { if (strpos($field, 'price') !== false) {
/** * 通过一个数组,分析出其中的某些字段,并返回 * @example * $a = [['a'=>1],['a'=>4,'b'=>2],['a'=>34,'c'=>25],['b'=>24,'c'=>56],]; * search_fields($a,'a,c') 得到结果:[1,3,34,25,56]; * * @param array $data 输入的数据 * @param string $keys 需要查找的KEY,可以多项 * @return array 返回一个符合该KEY的数组 */ function search_fields($data, $keys) { if (empty($data)) { return array(); } $keys = _array_selector_subkey($keys); $result = array(); foreach ($data as $key => $value) { if (is_array($value)) { $result = array_merge($result, search_fields($value, $keys)); } else { if (in_array($key, $keys)) { $result[] = $value; } } } return array_unique($result); }