function og_nodeapi in Organic groups 5.2
Same name and namespace in other branches
- 5.8 og.module \og_nodeapi()
- 5 og.module \og_nodeapi()
- 5.3 og.module \og_nodeapi()
- 5.7 og.module \og_nodeapi()
- 6.2 og.module \og_nodeapi()
- 6 og.module \og_nodeapi()
Implementation of hook_nodeapi().
File
- ./
og.module, line 1258
Code
function og_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'view':
$group_node = og_get_group_context();
if ($group_node && $page && $node->og_groups) {
// set breadcrumb and title on non group nodes
$bc[] = array(
'path' => "og",
'title' => t('Groups'),
);
$bc[] = array(
'path' => "node/{$group_node->nid}",
'title' => $group_node->title,
);
$bc[] = array(
'path' => "node/{$node->nid}",
'title' => $node->title,
);
menu_set_location($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);
}
if ($grps = og_get_node_groups($node)) {
// TODO: Refactor so we don't need 2 arrays.
$node->og_groups = array_keys($grps);
$node->og_groups_names = array_values($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;
}
break;
case 'validate':
if (og_is_group_type($node->type)) {
og_validate_group($node);
}
else {
// Ensure that a group is selected if groups are required. needed when author has no groups. In other cases, fapi does the validation
if (!in_array($node->type, variable_get('og_omitted', array())) && variable_get('og_audience_required', FALSE) && !user_access('administer nodes')) {
if (!isset($node->og_groups)) {
form_set_error('title', t('You must !join before posting on this web site.', array(
'!join' => l(t('join a group'), 'og'),
)));
}
}
}
break;
case 'submit':
og_submit_group($node);
break;
case 'prepare':
// TODO: some people don't like forcing comments to disabled for groups.
if (og_is_group_type($node->type)) {
$node->comment = COMMENT_NODE_DISABLED;
}
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 subscriber
og_save_subscription($node->nid, $node->uid, array(
'is_active' => 1,
'is_admin' => 1,
));
$account = user_load(array(
'uid' => $node->uid,
));
$variables = array(
'@group' => $node->title,
'!group_url' => url("node/{$node->nid}", NULL, NULL, TRUE),
'@username' => $account->name,
'!invite_url' => url("og/invite/{$node->nid}", NULL, NULL, TRUE),
);
// alert the user that they are now the admin of the group
$from = variable_get('site_mail', ini_get('sendmail_from'));
drupal_mail('og_new_admin', $account->mail, _og_user_mail_text('og_new_admin_subject', $variables), _og_user_mail_text('og_new_admin_body', $variables), $from);
}
elseif (!og_is_omitted_type($node->type)) {
og_save_ancestry($node);
}
// TODO: move this to cron to help give time to fix typos, and help scaling. create new module
// implementing an SMTP library that uses cron.
if (!module_exists('og2list')) {
if ($node->status) {
$node->msgid = "{$node->nid}-0" . og_msgid_server();
og_mail(node_get_types('name', $node), $node);
}
}
break;
case 'update':
if (og_is_group_type($node->type)) {
og_update_group($node);
// make sure the node owner is a full powered subscriber
og_save_subscription($node->nid, $node->uid, array(
'is_active' => 1,
'is_admin' => 1,
));
}
elseif (!og_is_omitted_type($node->type)) {
og_save_ancestry($node);
}
break;
case 'search result':
// TODO: add group info
break;
case 'rss item':
if ($node->og_groups) {
foreach ($node->og_groups as $cnt => $gid) {
// TODO: should be absolute link. core bug.
$append['og_links'] = array(
'title' => $node->og_groups_names[$cnt],
'href' => "node/{$gid}",
);
$ret[] = array(
'key' => 'group',
'value' => check_plain($node->og_groups_names[$cnt]),
'attributes' => array(
'domain' => url('node/' . $gid, NULL, NULL, TRUE),
),
);
}
// to get these modifications to work on 4.7, one needs to patch as per http://drupal.org/node/41703
$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;
}
}