Same name and namespace in other branches
- 4.7.x modules/node.module \node_search()
- 5.x modules/node/node.module \node_search()
- 6.x modules/node/node.module \node_search()
Implementation of hook_search().
File
- modules/
node.module, line 552 - The core that allows content to be submitted to the site.
Code
function node_search($op = 'search', $keys = null) {
switch ($op) {
case 'name':
return t('content');
case 'reset':
variable_del('node_cron_last');
return;
case 'status':
$last = variable_get('node_cron_last', 0);
$total = db_result(db_query('SELECT COUNT(*) FROM {node} WHERE status = 1 AND moderate = 0'));
$remaining = db_result(db_query('SELECT COUNT(*) FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE n.status = 1 AND n.moderate = 0 AND (n.created > %d OR n.changed > %d OR c.last_comment_timestamp > %d)', $last, $last, $last));
return array(
'remaining' => $remaining,
'total' => $total,
);
case 'search':
list($join, $where) = _db_rewrite_sql();
$find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid ' . $join . ' INNER JOIN {users} u ON n.uid = u.uid', 'n.status = 1' . (empty($where) ? '' : ' AND ' . $where));
$results = array();
foreach ($find as $item) {
$node = node_load(array(
'nid' => $item,
));
// Get node output (filtered and with module-specific fields).
if (node_hook($node, 'view')) {
node_invoke($node, 'view', false, false);
}
else {
$node = node_prepare($node, false);
}
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi($node, 'view', false, false);
$extra = node_invoke_nodeapi($node, 'search result');
$results[] = array(
'link' => url('node/' . $item),
'type' => node_invoke($node, 'node_name'),
'title' => $node->title,
'user' => format_name($node),
'date' => $node->changed,
'extra' => $extra,
'snippet' => search_excerpt($keys, $node->body),
);
}
return $results;
}
}