function twitter_actions_set_status_action in Twitter 6.3
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.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.4 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 Drupal action. Sends an email.
1 string reference to 'twitter_actions_set_status_action'
- twitter_actions_rules_action_info_alter in twitter_actions/
twitter_actions.rules.inc - Implementation of hook_rules_action_info_alter().
File
- twitter_actions/
twitter_actions.module, line 123 - 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');
switch ($context['hook']) {
case 'nodeapi':
case 'workflow':
// Because this is not an action of type 'node' the node
// will not be passed as $object, but it will still be available
// in $context.
$node = $context['node'];
break;
// The comment hook provides nid, in $context.
case 'comment':
$comment = $context['comment'];
$node = node_load($comment->nid);
case 'user':
// Because this is not an action of type 'user' the user
// object is not passed as $object, but it will still be available
// in $context.
$account = $context['account'];
if (isset($context['node'])) {
$node = $context['node'];
}
elseif (isset($context['recipient']) && $context['recipient'] == '%author') {
// If we don't have a node, we don't have a node author.
watchdog('error', 'Cannot use %author token in this context.');
return;
}
break;
case 'taxonomy':
$account = $user;
$vocabulary = taxonomy_vocabulary_load($object->vid);
$variables = array_merge($variables, array(
'%term_name' => $object->name,
'%term_description' => $object->description,
'%term_id' => $object->tid,
'%vocabulary_name' => $vocabulary->name,
'%vocabulary_description' => $vocabulary->description,
'%vocabulary_id' => $vocabulary->vid,
));
break;
default:
// We are being called directly.
$node = $object;
}
if (isset($node)) {
if (!isset($account)) {
$account = user_load(array(
'uid' => $node->uid,
));
}
if (isset($context['recipient']) && $context['recipient'] == '%author') {
$recipient = $account->mail;
}
}
$variables['%username'] = $account->name;
// Node-based variable translation is only available if we have a node.
if (isset($node) && is_object($node)) {
$variables = array_merge($variables, array(
'%uid' => $node->uid,
'%node_url' => url('node/' . $node->nid, array(
'absolute' => TRUE,
)),
'%node_type' => node_get_types('name', $node),
'%title' => $node->title,
'%teaser' => $node->teaser,
'%body' => $node->body,
));
}
// 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);
// If token module is available, process status to do the token replacement
if (module_exists('token')) {
// Token replacement for the main context hooks other than node
$context_list = array(
'workflow',
'comment',
'user',
'taxonomy',
);
if (in_array($context['hook'], $context_list, TRUE)) {
$message = token_replace($message, $context['hook'], $object);
}
// then if we have a node object, also do it for the node
if (isset($node) && is_object($node)) {
$message = token_replace($message, 'node', $node);
}
}
module_load_include('inc', 'twitter');
$twitter_account = twitter_account_load($context['twitter_uid']);
twitter_set_status($twitter_account, $message);
}