You are here

function sms_actions_do in SMS Framework 7

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

Executes actions defined by sms_actions module.

Parameters

string $command: The command to execute.

string $number: The phone number associated with the action.

string $message: The message to be sent.

1 call to sms_actions_do()
sms_actions_sms_incoming in modules/sms_actions/sms_actions.module
Implementation of hook_sms_incoming().

File

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

Code

function sms_actions_do($command, $number, $message) {

  // Keep objects for reuse so that changes actions make to objects can persist.
  static $objects;
  $aids = trigger_get_assigned_actions($command->hook) + trigger_get_assigned_actions('sms_actions');
  if (!$aids) {
    return;
  }
  $context = array(
    'group' => 'sms_actions',
    'hook' => $command->hook,
    'from' => $number,
  );
  foreach ($aids as $aid => $action_info) {
    $type = $action_info['type'];
    if ($type != 'sms') {
      if ($type == 'node') {
        preg_match('!^[A-z0-9\\-]+\\s(.+)$!', $message, $matches);
        $params = explode(' ', $matches[1]);
        if ($node = node_load($params[0])) {
          if (!isset($objects[$type])) {
            $objects[$type] = _trigger_normalize_comment_context($type, $node);
          }
          $context['group'] = 'node';
          actions_do($aid, $objects[$type], $context);
        }
      }
    }
    else {
      if (!isset($objects[$type])) {
        $objects[$type] = (object) array(
          'message' => $message,
          'from' => $number,
        );
      }
      actions_do($aid, $objects[$type], $context);
    }
  }
}