function og_nodeapi in Organic groups 6
Same name and namespace in other branches
- 5.8 og.module \og_nodeapi()
- 5 og.module \og_nodeapi()
- 5.2 og.module \og_nodeapi()
- 5.3 og.module \og_nodeapi()
- 5.7 og.module \og_nodeapi()
- 6.2 og.module \og_nodeapi()
Implementation of hook_nodeapi().
1 string reference to 'og_nodeapi'
- og_form_add_og_audience in ./
og.module - Helper method to add OG audience fields to a given form. This is lives in a separate function from og_form_alter() so it can be shared by other OG contrib modules.
File
- ./
og.module, line 1575
Code
function og_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
global $user;
switch ($op) {
case 'view':
$group_node = og_get_group_context();
if ($group_node && $page && !empty($node->og_groups)) {
$bc = og_get_breadcrumb($group_node);
drupal_set_breadcrumb($bc);
}
if (og_is_group_type($node->type)) {
og_view_group($node, $teaser, $page);
}
break;
case 'load':
if (og_is_group_type($node->type)) {
og_load_group($node);
}
elseif ($grps = og_get_node_groups($node)) {
// TODO: Refactor so we don't need 2 arrays.
$node->og_groups = drupal_map_assoc(array_keys($grps));
$node->og_groups_both = $grps;
$public = db_result(db_query_range("SELECT is_public FROM {og_ancestry} WHERE nid = %d", $node->nid, 0, 1));
$node->og_public = $public ? TRUE : FALSE;
}
else {
$node->og_groups = $node->og_groups_both = array();
}
break;
case 'validate':
// Ensure that a group is selected if groups are required. needed when
// author has no groups. In other cases, fapi does the validation.
if (og_is_group_post_type($node->type) && variable_get('og_audience_required', FALSE) && !user_access('administer nodes')) {
if (!isset($node->og_groups)) {
form_set_error('title', t('You must <a href="@join">join a group</a> before posting on this web site.', array(
'@join' => url('og'),
)));
}
}
break;
case 'presave':
og_presave_group($node);
break;
case 'delete':
$sql = "DELETE FROM {og} WHERE nid = %d";
db_query($sql, $node->nid);
$sql = "DELETE FROM {og_ancestry} WHERE nid = %d";
db_query($sql, $node->nid);
$sql = "DELETE FROM {og_uid} WHERE nid = %d";
db_query($sql, $node->nid);
break;
case 'insert':
if (og_is_group_type($node->type)) {
og_insert_group($node);
// Make sure the node owner is a full powered member.
og_save_subscription($node->nid, $node->uid, array(
'is_active' => 1,
'is_admin' => 1,
));
// Load new group into $user->og_groups so that author can get redirected to the new group
if ($node->uid == $user->uid) {
$user->og_groups = og_get_subscriptions($node->uid, 1, TRUE);
}
$account = user_load(array(
'uid' => $node->uid,
));
$variables = array(
'@group' => $node->title,
'!group_url' => url("node/{$node->nid}", array(
'absolute' => TRUE,
)),
'@username' => $account->name,
'!invite_url' => url("og/invite/{$node->nid}", array(
'absolute' => TRUE,
)),
);
$message = array(
'subject' => _og_mail_text('og_new_admin_subject', $variables),
'body' => _og_mail_text('og_new_admin_body', $variables),
);
// Skip the alert if we are auto-generating nodes.
if (empty($node->devel_generate)) {
// Alert the user that they are now the admin of the group.
module_invoke_all('og', 'admin new', $node->nid, $account->uid, $message);
}
}
else {
og_save_ancestry($node);
}
break;
case 'update':
if (og_is_group_type($node->type)) {
og_update_group($node);
// make sure the node owner is a full powered member
og_save_subscription($node->nid, $node->uid, array(
'is_active' => 1,
'is_admin' => 1,
));
// load new group into $user->og_groups so that author can get redirected to the new group
if ($node->uid == $user->uid) {
$user->og_groups = og_get_subscriptions($user->uid, 1, TRUE);
}
}
else {
og_save_ancestry($node);
}
break;
case 'search result':
// Similar code in og_preprocess_node()
$current_groups['accessible'] = array();
if ($node->og_groups) {
$current_groups = og_node_groups_distinguish($node->og_groups_both, FALSE);
}
$msg = format_plural(count($current_groups['accessible']), '1 group', '@count groups');
return array(
'og_msg' => $msg,
);
// TODOL: bad formatting. commented out.
// foreach ($current_groups['accessible'] as $gid => $item) {
// $og_links['og_'. $gid] = array('title' => $item['title'], 'href' => "node/$gid");
// }
// return theme('links', $og_links, array('class' => 'groups links'));
break;
case 'rss item':
if (isset($node->og_groups)) {
$ret = array();
$append = array();
foreach ($node->og_groups_both as $gid => $title) {
// TODO: should be absolute link. core bug.
$append['og_links'] = array(
'title' => $title,
'href' => "node/{$gid}",
);
$ret[] = array(
'key' => 'group',
'value' => check_plain($title),
'attributes' => array(
'domain' => url("node/{$gid}", array(
'absolute' => TRUE,
)),
'xmlns' => 'http://drupal.org/project/og',
),
);
}
$node->body .= '<div class="og_rss_groups">' . theme('links', $append) . '</div>';
$node->teaser .= '<div class="og_rss_groups">' . theme('links', $append) . '</div>';
return $ret;
}
break;
}
}