function realname_nodeapi in Real Name 6
Same name and namespace in other branches
- 5 realname.module \realname_nodeapi()
Implements hook_nodeapi().
3 string references to 'realname_nodeapi'
- realname_admin_general in ./
realname.admin.inc - realname_admin_general_submit in ./
realname.admin.inc - realname_uninstall in ./
realname.install - Implementation of hook_uninstall().
File
- ./
realname.module, line 426
Code
function realname_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
static $type;
static $accounts = array();
if (!user_access('use realname')) {
return;
}
// NickSI: Yes, we will have another switch later but I would like to separate table update with other processing
// Just delete the old nickname from the table. New one is automatically generated on next request.
if (variable_get('realname_profile_module', NULL) == 'content_profile' && module_exists('content_profile') && is_content_profile($node->type)) {
switch ($op) {
case 'update':
case 'insert':
case 'delete':
db_query('DELETE FROM {realname} WHERE uid = %d', $node->uid);
}
}
if (!variable_get('realname_nodeapi', FALSE)) {
return;
}
switch ($op) {
case 'view':
// Don't operate on the node type that we are using.
if (!isset($type)) {
$type = variable_get('realname_profile_type', NULL);
}
if ($node->type == $type) {
break;
}
// Node is being loaded.
// Save the username that is already there.
$node->realname_save = $node->name;
if (!isset($accounts[$node->uid])) {
$accounts[$node->uid] = realname_get_user($node->uid);
}
$account = $accounts[$node->uid];
$node->realname = $node->name = $account->name;
$node->homepage = isset($account->homepage) ? $account->homepage : NULL;
break;
case 'prepare':
// Node is about to be edited.
// Reset the username or save will fail.
if (isset($node->realname_save)) {
$node->name = $node->realname_save;
}
break;
}
}