function twitter_actions_set_status_action in Twitter 7.4
Same name and namespace in other branches
- 6.5 twitter_actions/twitter_actions.module \twitter_actions_set_status_action()
- 6.2 twitter_actions/twitter_actions.module \twitter_actions_set_status_action()
- 6.3 twitter_actions/twitter_actions.module \twitter_actions_set_status_action()
- 6.4 twitter_actions/twitter_actions.module \twitter_actions_set_status_action()
- 7.6 twitter_actions/twitter_actions.module \twitter_actions_set_status_action()
- 7.3 twitter_actions/twitter_actions.module \twitter_actions_set_status_action()
- 7.5 twitter_actions/twitter_actions.module \twitter_actions_set_status_action()
Implementation of a configurable Twitter action. @todo Implementation for language negotiation for the body and sumary. Also need implementation for bodies with multiple values. Right now it is hard coded and it will only get body and summary for 'und' language and only the first value of the body field. If the final message is over 140 chars, there is no feedback to the user.
File
- twitter_actions/
twitter_actions.module, line 105 - Exposes Drupal actions for sending Twitter messages.
Code
function twitter_actions_set_status_action($object, $context) {
global $user;
$variables['%site_name'] = variable_get('site_name', 'Drupal');
// Seting variables array depending on action's group
switch ($context['group']) {
case 'node':
$node = $context['node'];
if (isset($node)) {
$variables = array_merge($variables, array(
'%uid' => $node->uid,
'%username' => $node->name,
'%node_url' => url('node/' . $node->nid, array(
'absolute' => TRUE,
)),
'%node_type' => node_type_get_name($node),
'%title' => $node->title,
'%summary' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['summary'] : '',
'%body' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['value'] : '',
));
}
break;
case 'comment':
$node = node_load($context['comment']->nid);
if (isset($node)) {
$variables = array_merge($variables, array(
'%uid' => $context['comment']->uid,
'%username' => $context['comment']->name,
'%node_url' => url('node/' . $node->nid, array(
'absolute' => TRUE,
)),
'%node_type' => node_type_get_name($node),
'%title' => $node->title,
'%summary' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['summary'] : '',
'%body' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['value'] : '',
));
}
break;
case 'user':
$variables['%username'] = $context['user']->name;
break;
case 'cron':
break;
default:
// We are being called directly.
$node = $object;
if (isset($node) && is_object($node)) {
$variables = array_merge($variables, array(
'%uid' => $node->uid,
'%username' => $node->name,
'%node_url' => url('node/' . $node->nid, array(
'absolute' => TRUE,
)),
'%node_type' => node_type_get_name($node),
'%title' => $node->title,
'%summary' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['summary'] : '',
'%body' => isset($node->body['und'][0]['value']) ? $node->body['und'][0]['value'] : '',
));
}
}
// Only make a tinyurl if it was asked for.
if (strstr($context['message'], '%tinyurl') !== FALSE) {
$variables = array_merge($variables, array(
'%tinyurl' => twitter_shorten_url(url('node/' . $node->nid, array(
'absolute' => TRUE,
))),
));
}
$message = strtr($context['message'], $variables);
module_load_include('inc', 'twitter');
$twitter_account = twitter_account_load($context['twitter_uid']);
twitter_set_status($twitter_account, $message);
}