View source
<?php
function activity_log_rules_data_type_info() {
return array(
'message' => array(
'label' => t('logged heartbeat message in the most basic form'),
'class' => 'rules_data_type_heartbeat_message',
'identifiable' => FALSE,
),
);
}
class rules_data_type_heartbeat_message extends rules_data_type {
}
function user_activity_rules_action_info() {
$info = array(
'user_activity_rules_default_action' => array(
'label' => t('Logs relational user activity'),
'eval input' => array(
'event_param',
'uid_param',
'uid_target_param',
'nid_target_param',
'message_param',
'message_concat_param',
'variables_param',
),
'help' => 'Create a relation between a user and others when handling a node.',
'module' => 'User activity',
),
);
return $info;
}
function user_activity_rules_default_action_form($settings, &$form) {
$settings += array(
'event_param' => '',
'uid_param' => '',
'uid_target_param' => '',
'nid_target_param' => '',
'message_param' => '',
'message_concat_param' => '',
'variables_param' => '',
);
$result = db_query("SELECT event FROM {heartbeat_messages}");
$options = array();
while ($row = db_fetch_object($result)) {
$options[$row->event] = $row->event;
}
$form['settings']['event_param'] = array(
'#type' => 'select',
'#title' => t('The event'),
'#options' => $options,
'#default_value' => $settings['event_param'],
'#description' => t('The event'),
);
$form['settings']['uid_param'] = array(
'#type' => 'textfield',
'#size' => '15',
'#maxsize' => '25',
'#title' => t('User'),
'#default_value' => $settings['uid_param'],
'#description' => t('The user doing the activity'),
);
$form['settings']['uid_target_param'] = array(
'#type' => 'textfield',
'#size' => '15',
'#maxsize' => '25',
'#title' => t('User target'),
'#default_value' => $settings['uid_target_param'],
'#description' => t('The user target of the activity'),
);
$form['settings']['nid_target_param'] = array(
'#type' => 'textfield',
'#size' => '15',
'#maxsize' => '25',
'#title' => t('Node target'),
'#default_value' => $settings['nid_target_param'],
'#description' => t('The node target of the activity'),
);
$form['settings']['message_param'] = array(
'#type' => 'textarea',
'#rows' => 1,
'#title' => t('The message'),
'#default_value' => $settings['message_param'],
'#description' => t('The message'),
);
$form['settings']['message_concat_param'] = array(
'#type' => 'textarea',
'#rows' => 1,
'#title' => t('The message if it needs to be concatenated in general heartbeat views.'),
'#default_value' => $settings['message_concat_param'],
'#description' => t('The message concatenation string'),
);
$form['settings']['variables_param'] = array(
'#type' => 'textarea',
'#title' => t('The variables area.'),
'#default_value' => $settings['variables_param'],
'#description' => t('The variables, leave empty or use with care! <br /> Extra modular stuff goes here with the synthax:<br /><b>var1:value1;var2:value2;va</b> ...'),
);
}
function user_activity_rules_default_action_submit(&$settings, $form, $form_state) {
$params = $form_state['values']['settings'];
db_query("UPDATE {heartbeat_messages} SET message ='%s', message_concat = '%s', variables = '%s' \n WHERE event = '%s'", $params['message_param'], $params['message_concat_param'], $params['variables_param'], $params['event_param']);
}
function user_activity_rules_default_action($settings, $form = array(), $event_info = array()) {
$data = array();
if (is_array($settings)) {
$data['uid'] = $settings['uid_param'];
$data['uid_target'] = $settings['uid_target_param'];
$data['nid_target'] = $settings['nid_target_param'];
$data['message'] = t($settings['message_param']);
$data['message_concat'] = t($settings['message_concat_param']);
$data['variables'] = $settings['variables_param'];
$data['event'] = $settings['event_param'];
$data['hid'] = heartbeat_event_id($settings['event_param']);
}
user_activity_log($data);
}
function user_activity_rules_condition_info() {
}
function user_activity_token_list($type = 'all') {
if ($type == 'boolean') {
$tokens['boolean']['1-or-0'] = t("1 for true, 0 for false");
}
if ($type == 'node') {
$tokens['node']['title-link'] = t("The node's title with a link to it");
}
if ($type == 'user') {
$tokens['node']['user-name-url'] = t("The users name with a link to it");
$tokens['user']['user-profile-url'] = t("The users name with a link to his/her profile page. <strong>USE ONLY when url-path is set to profile/username </strong>");
}
return $tokens;
}
function user_activity_token_values($type, $object = NULL, $options = array()) {
$values = array();
switch ($type) {
case 'heartbeat_message':
$values['raw'] = $object;
break;
case 'boolean':
$values['1-or-0'] = $object ? '1' : '0';
break;
case 'node':
$values['title-link'] = l($object->title, 'node/' . $object->nid);
break;
case 'user':
$values['user-name-url'] = l($object->name, 'user/' . $object->uid);
$values['user-profile-url'] = l($object->name, 'profile/' . $object->name);
break;
}
return $values;
}