function node_import_nodereference in Node import 5
Helper function to get a node from a string. This function will return the nid of the node found or NULL if no node matching the string was found.
If the string provided is an integer, then this function will assume that the node is identified by nid.
Otherwise, the function will lookup a node with a title matching the string.
Parameters
$title: String. Title or nid of a node.
Return value
Nid of the node found, or NULL.
2 calls to node_import_nodereference()
- book_node_import_prepare in supported/
book.inc - Implementation of hook_node_import_prepare().
- content_node_import_prepare in supported/
cck/ content.inc - Implementation of hook_node_import_prepare().
File
- ./
node_import.api.inc, line 179
Code
function node_import_nodereference($title) {
static $nids = array();
$title = trim($title);
if (!isset($nids[$title])) {
$nids[$title] = NULL;
if (strlen($title) > 0 && is_numeric($title) && intval($title) > 0 && ($node = node_load(intval($title), NULL, TRUE))) {
$nids[$title] = $node->nid;
}
else {
if (strlen($title) > 0 && ($node = db_fetch_object(db_query("SELECT nid FROM {node} WHERE title = '%s'", $title)))) {
$nids[$title] = $node->nid;
}
else {
if (strlen($title) > 0 && ($node = db_fetch_object(db_query("SELECT nid FROM {node} WHERE title SOUNDS LIKE '%s'", $title)))) {
$nids[$title] = $node->nid;
}
}
}
}
return $nids[$title];
}