401, 'title' => 'Unauthorized', 'detail' => $lang['error-permissiondenied']); echo json_encode($return); exit(); } $return = array(); $found_node_by_ref = array(); $current_node_pointer = 0; if ($node > 0 && get_node($node, $found_node_by_ref)) { $found_node_by_ref['name'] = i18n_get_translated($found_node_by_ref['name']); $return['data'] = $found_node_by_ref; echo json_encode($return); exit(); } // Fuzzy search by node name: // Translate (i18l) all options and return those that have a match for what client code searched (fuzzy searching still applies) if ($name != "") { // Set $keywords_remove_diacritics so as to only add versions with diacritics to return array if none are in the submitted string $keywords_remove_diacritics = mb_strlen($name) === strlen($name); $name = normalize_keyword($name); foreach (get_nodes($resource_type_field, null, true, null, $rows, $name) as $node) { if ($rows == $current_node_pointer) { break; } $i18l_name = i18n_get_translated($node['name']); $compare = normalize_keyword($i18l_name); // Skip any translated (i18l) names that don't contain what client code searched for if (false === mb_strpos(mb_strtolower($compare), mb_strtolower($name))) { continue; } $node['name'] = $i18l_name; $return['data'][] = $node; // Increment only when valid nodes have been added to the result set $current_node_pointer++; } } // Search did not return any results back. This is still considered a successful request! if (($node > 0 || $name != "") && !isset($return['data']) && 0 === count($return)) { $return['data'] = array(); } // Only resource type field specified? That means client code is querying for all options of this field if ($resource_type_field > 0 && $name == "") { foreach (get_nodes($resource_type_field, null, true) as $node) { $node['name'] = i18n_get_translated($node["name"]); $return['data'][] = $node; } } // If by this point we still don't have a response for the request, // create one now telling client code this is a bad request if (0 === count($return)) { $return['error'] = array( 'status' => 400, 'title' => 'Bad Request', 'detail' => 'The request could not be handled by get_nodes.php!'); } echo json_encode($return); exit();