View source
<?php
function og_actions_action_info() {
$actions = array(
'og_remove_groups_action' => array(
'type' => 'node',
'description' => t('Remove post from all groups'),
'configurable' => FALSE,
'behavior' => array(
'changes_node_property',
),
'hooks' => array(
'nodeapi' => array(
'insert',
'update',
),
),
),
'og_add_group_action' => array(
'type' => 'node',
'description' => t('Add post to the specified group'),
'behavior' => array(
'changes_node_property',
),
'configurable' => TRUE,
'hooks' => array(
'nodeapi' => array(
'insert',
'update',
),
),
),
'og_remove_group_action' => array(
'type' => 'node',
'description' => t('Remove post from the specified group'),
'behavior' => array(
'changes_node_property',
),
'configurable' => TRUE,
'hooks' => array(
'nodeapi' => array(
'insert',
'update',
),
),
),
'og_subscribe_user_action' => array(
'type' => 'user',
'description' => t('Subscribe user to the specified group'),
'configurable' => TRUE,
'hooks' => array(),
),
'og_unsubscribe_user_action' => array(
'type' => 'user',
'description' => t('Unsubscribe user from the specified group'),
'configurable' => TRUE,
'hooks' => array(),
),
'og_promote_user_action' => array(
'type' => 'user',
'description' => t('Promote user to an administrator in the specified group'),
'configurable' => TRUE,
'hooks' => array(),
),
'og_demote_user_action' => array(
'type' => 'user',
'description' => t('Demote user from an administrator in the specified group'),
'configurable' => TRUE,
'hooks' => array(),
),
'og_approve_user_action' => array(
'type' => 'user',
'description' => t('Approve user subscription to the specified group'),
'configurable' => TRUE,
'hooks' => array(),
),
'og_deny_user_action' => array(
'type' => 'user',
'description' => t('Deny user subscription to the specified group'),
'configurable' => TRUE,
'hooks' => array(),
),
);
if (module_exists('og_access')) {
$actions += array(
'og_make_public_action' => array(
'type' => 'node',
'description' => t('Make post publicly visible'),
'behavior' => array(
'changes_node_property',
),
'configurable' => FALSE,
'hooks' => array(
'nodeapi' => array(
'insert',
'update',
),
),
),
'og_make_private_action' => array(
'type' => 'node',
'description' => t('Make post private to its groups'),
'behavior' => array(
'changes_node_property',
),
'configurable' => FALSE,
'hooks' => array(
'nodeapi' => array(
'insert',
'update',
),
),
),
);
}
return $actions;
}
function og_make_public_action($node, $context) {
if (isset($node->og_groups)) {
$node->og_public = 1;
watchdog('action', 'Set node %id to public.', array(
'%id' => intval($node->nid),
));
}
}
function og_make_private_action($node, $context) {
if (isset($node->og_groups)) {
$node->og_public = 0;
watchdog('action', 'Set node %id to private.', array(
'%id' => intval($node->nid),
));
}
}
function og_remove_groups_action($node, $context) {
if (!empty($node->og_groups)) {
$node->og_groups = array();
watchdog('action', 'Removed node %id from all groups.', array(
'%id' => intval($node->nid),
));
}
}
function og_add_group_action($node, $context) {
if (isset($context['group'])) {
$node->og_groups[$context['group']] = $context['group'];
watchdog('action', 'Added node id %id to %group.', array(
'%id' => intval($node->nid),
'%group' => $context['group'],
));
}
}
function og_add_group_action_form($context) {
if (!isset($context['group'])) {
$context['group'] = '';
}
$groups = og_all_groups_options();
if (count($groups)) {
$form = array();
$form['group'] = array(
'#type' => 'select',
'#title' => t('Group'),
'#options' => $groups,
'#description' => t('Select the group to add to the node.'),
'#default_value' => $context['group'],
'#required' => TRUE,
);
}
else {
drupal_set_message(t('Please <a href="!url">create</a> a group first.', array(
'!url' => url('admin/content'),
)));
}
return $form;
}
function og_add_group_action_submit($form, &$form_state) {
return array(
'group' => $form_state['values']['group'],
);
}
function og_remove_group_action($node, $context) {
if (isset($context['group'])) {
foreach ($node->og_groups as $key => $gid) {
if ($gid == $context['group']) {
unset($node->og_groups[$key]);
}
}
watchdog('action', 'Removed node id %id from %group.', array(
'%id' => intval($node->nid),
'%group' => $context['group'],
));
}
}
function og_remove_group_action_form($context) {
if (!isset($context['group'])) {
$context['group'] = '';
}
$groups = og_all_groups_options();
if (count($groups)) {
$form = array();
$form['group'] = array(
'#type' => 'select',
'#title' => t('Group'),
'#options' => $groups,
'#description' => t('Select the group to remove from the node.'),
'#default_value' => $context['group'],
'#required' => TRUE,
);
}
else {
drupal_set_message(t('There are no groups. You must have at least one existing group with nodes assigned to use this action.'));
}
return $form;
}
function og_remove_group_action_submit($form, &$form_state) {
return array(
'group' => $form_state['values']['group'],
);
}
function og_subscribe_user_action($account, $context) {
if (isset($context['group'])) {
og_save_subscription($context['group'], $account->uid, array(
'is_active' => 1,
));
watchdog('action', 'Subscribed user %name to %group.', array(
'%name' => $account->name,
'%group' => $context['group'],
));
}
}
function og_subscribe_user_action_form($context) {
$form = array();
if (!isset($context['group'])) {
$context['group'] = '';
}
$groups = og_all_groups_options();
if (count($groups)) {
$form['group'] = array(
'#type' => 'select',
'#title' => t('Group'),
'#options' => $groups,
'#description' => t('Select the group to which this user should be subscribed.'),
'#default_value' => $context['group'],
'#required' => TRUE,
);
}
else {
drupal_set_message(t('Please <a href="!url">create</a> a group first.', array(
'!url' => url('admin/content'),
)));
}
return $form;
}
function og_subscribe_user_action_submit($form, &$form_state) {
return array(
'group' => $form_state['values']['group'],
);
}
function og_unsubscribe_user_action($account, $context) {
if (isset($context['group'])) {
og_delete_subscription($context['group'], $account->uid);
watchdog('action', 'Unsubscribed user %name to %group.', array(
'%name' => $account->name,
'%group' => $context['group'],
));
}
}
function og_unsubscribe_user_action_form($context) {
$form = array();
if (!isset($context['group'])) {
$context['group'] = '';
}
$groups = og_all_groups_options();
if (count($groups)) {
$form['group'] = array(
'#type' => 'select',
'#title' => t('Group'),
'#options' => $groups,
'#description' => t('Select the group to which this user should be unsubscribed.'),
'#default_value' => $context['group'],
'#required' => TRUE,
);
}
else {
drupal_set_message(t('Please <a href="!url">create</a> a group first.', array(
'!url' => url('admin/conten
t'),
)));
}
return $form;
}
function og_unsubscribe_user_action_submit($form, &$form_state) {
return array(
'group' => $form_state['values']['group'],
);
}
function og_promote_user_action($account, $context) {
if (isset($context['group'])) {
og_save_subscription($context['group'], $account->uid, array(
'is_admin' => 1,
));
watchdog('action', '%name was promoted to <em>group administrator</em> in %group.', array(
'%name' => $account->name,
'%group' => $context['group'],
));
}
}
function og_promote_user_action_form($context) {
$form = array();
if (!isset($context['group'])) {
$context['group'] = '';
}
$groups = og_all_groups_options();
if (count($groups)) {
$form['group'] = array(
'#type' => 'select',
'#title' => t('Group'),
'#options' => $groups,
'#description' => t('Select the group to which this user should be promoted.'),
'#default_value' => $context['group'],
'#required' => TRUE,
);
}
else {
drupal_set_message(t('Please <a href="!url">create</a> a group first.', array(
'!url' => url('admin/conten
t'),
)));
}
return $form;
}
function og_promote_user_action_submit($form, &$form_state) {
return array(
'group' => $form_state['values']['group'],
);
}
function og_demote_user_action($account, $context) {
if (isset($context['group'])) {
og_save_subscription($context['group'], $account->uid, array(
'is_admin' => 0,
));
watchdog('action', 'Demoted user %name from <em>group administrator</em> in %group.', array(
'%name' => $account->name,
'%group' => $context['group'],
));
}
}
function og_demote_user_action_form($context) {
$form = array();
if (!isset($context['group'])) {
$context['group'] = '';
}
$groups = og_all_groups_options();
if (count($groups)) {
$form['group'] = array(
'#type' => 'select',
'#title' => t('Group'),
'#options' => $groups,
'#description' => t('Select the group from which this user should be demoted.'),
'#default_value' => $context['group'],
'#required' => TRUE,
);
}
else {
drupal_set_message(t('Please <a href="!url">create</a> a group first.', array(
'!url' => url('admin/conten
t'),
)));
}
return $form;
}
function og_demote_user_action_submit($form, &$form_state) {
return array(
'group' => $form_state['values']['group'],
);
}
function og_approve_user_action($account, $context) {
if (isset($context['group'])) {
og_save_subscription($context['group'], $account->uid, array(
'is_active' => 1,
));
watchdog('action', "Approved user %name's subscription to %group.", array(
'%name' => $account->name,
'%group' => $context['group'],
));
}
}
function og_approve_user_action_form($context) {
$form = array();
if (!isset($context['group'])) {
$context['group'] = '';
}
$groups = og_all_groups_options();
if (count($groups)) {
$form['group'] = array(
'#type' => 'select',
'#title' => t('Group'),
'#options' => $groups,
'#description' => t('Select the group whose user subscription request should be approved.'),
'#default_value' => $context['group'],
'#required' => TRUE,
);
}
else {
drupal_set_message(t('Please <a href="!url">create</a> a group first.', array(
'!url' => url('admin/conten
t'),
)));
}
return $form;
}
function og_approve_user_action_submit($form, &$form_state) {
return array(
'group' => $form_state['values']['group'],
);
}
function og_deny_user_action($account, $context) {
if (isset($context['group'])) {
og_save_subscription($context['group'], $account->uid, array(
'is_active' => 0,
));
watchdog('action', "Denied user %name's subscription to %group.", array(
'%name' => $account->name,
'%group' => $context['group'],
));
}
}
function og_deny_user_action_form($context) {
$form = array();
if (!isset($context['group'])) {
$context['group'] = '';
}
$groups = og_all_groups_options();
if (count($groups)) {
$form['group'] = array(
'#type' => 'select',
'#title' => t('Group'),
'#options' => $groups,
'#description' => t('Select the group whose user subscription request should be denied.'),
'#default_value' => $context['group'],
'#required' => TRUE,
);
}
else {
drupal_set_message(t('Please <a href="!url">create</a> a group first.', array(
'!url' => url('admin/conten
t'),
)));
}
return $form;
}
function og_deny_user_action_submit($form, &$form_state) {
return array(
'group' => $form_state['values']['group'],
);
}
function og_actions_rules_action_info_alter(&$actions) {
foreach (array_keys(og_actions_action_info()) as $action_name) {
$actions['rules_core_' . $action_name]['module'] = 'Organic groups';
}
}