You are here

function sms_actions_send_action in SMS Framework 7

Same name and namespace in other branches
  1. 6.2 modules/sms_actions/sms_actions.module \sms_actions_send_action()
  2. 6 modules/sms_actions/sms_actions.module \sms_actions_send_action()

Implements the action sms_action_send_action.

Parameters

object $object: The object initiating the action.

array $context: The context in which the action is being triggered.

2 string references to 'sms_actions_send_action'
SmsActionWebTest::testSmsActionsActionsIntegration in modules/sms_actions/sms_actions.test
Tests integration with the actions module.
sms_actions_action_info_alter in modules/sms_actions/sms_actions.module
Implements hook_action_info_alter().

File

modules/sms_actions/sms_actions.module, line 201
Provides a "Send SMS" action and the ability to define custom triggers for incoming messages.

Code

function sms_actions_send_action($object, $context) {
  global $user;
  switch ($context['group']) {
    case 'node':
      $node = $context['node'];
      break;
    case 'comment':
      $comment = $context['comment'];
      $node = node_load($comment->nid);
      break;
    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. Use user_load() to pull in ->sms_user data as well.
      $account = user_load($context['account']->uid);
      $variables['%username'] = $account->name;
      if (isset($context['node'])) {
        $node = $context['node'];
      }
      elseif ($context['recipient'] == '%author') {

        // If we don't have a node, we don't have a node author.
        watchdog('error', t("Cannot use '%author' token in this context."));
        return;
      }
      break;
    case 'sms_actions':

      // We don't want the default: action for 'sms_actions' group.
      break;
    default:

      // Check context for node.
      if (!isset($object) && isset($context['node'])) {
        $node = $context['node'];
      }
      else {

        // We are being called directly.
        $node = $object;
      }
      break;
  }
  $number = $context['number'];
  $variables['%site_name'] = variable_get('site_name', 'Drupal');
  if (isset($node)) {
    if (!isset($account)) {
      $account = user_load($node->uid);
      $variables['%username'] = $account->name;
    }
    if ($context['author'] && $account->sms_user['status'] == 2) {
      $number = $account->sms_user['number'];
    }
    $names = node_type_get_names();
    $variables = array_merge($variables, array(
      '%uid' => $node->uid,
      '%node_url' => url('node/' . $node->nid, array(
        'absolute' => TRUE,
      )),
      '%node_type' => check_plain($names[$node->type]),
      '%title' => filter_xss($node->title),
      '%teaser' => filter_xss($node->teaser),
      '%body' => filter_xss($node->body),
    ));
  }
  $message = strtr($context['message'], $variables);
  if (isset($node) && $context['author'] && isset($account)) {
    sms_user_send($account->uid, $message);
  }
  else {
    sms_send($number, $message);
  }
}