function drupagram_actions_set_status_action in Drupagram 7
Implementation of a configurable Instagram actions. @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
- drupagram_actions/
drupagram_actions.module, line 117 - Exposes Drupal actions for sending Instagram messages.
Code
function drupagram_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' => drupagram_shorten_url(url('node/' . $node->nid, array(
'absolute' => TRUE,
))),
));
}
$message = strtr($context['message'], $variables);
module_load_include('inc', 'drupagram');
$drupagram_account = drupagram_account_load($context['drupagram_id']);
drupagram_set_status($drupagram_account, $message);
}