You are here

function sms_receive_receive in SMS Framework 5

1 string reference to 'sms_receive_receive'
sms_receive_menu in modules/sms_receive/sms_receive.module

File

modules/sms_receive/sms_receive.module, line 156

Code

function sms_receive_receive() {
  $message = sms_receive_parse();

  // Insert message into database, mostly for logging and debug right now
  $mid = db_next_id('{sms_messages}');
  db_query("INSERT INTO {sms_receive} (mid, number, message, time) VALUES(%d, '%s', '%s', '%s')", $mid, $message['from'], $message['text'], time());
  $node = sms_receive_process_message($message);

  // check if mail originates from an authenticated user
  // Can't do this as a hook to sms_user because we need to authenticate as this user
  $node = sms_receive_authenticate($node, $message);

  // we need to change the current user
  // this has to be done here to allow modules
  // to create users
  sms_receive_switch_user($node->uid);

  // modules may override node elements before submitting. they do so by returning the node.
  foreach (module_list() as $name) {
    if (module_hook($name, 'sms_receive')) {
      $function = $name . '_sms_receive';
      if (!($node = $function($node, $message))) {

        // Exit if a module has handled the submitted data.
        break;
      }
    }
  }
  if ($node) {
    if ($node->type == 'comment') {
      sms_receive_comment_submit($node);
    }
    else {
      sms_receive_node_submit($node);
    }
  }

  // switch back to original user
  sms_receive_switch_user();

  // Show what was received, mostly for debugging
  $output = 'Type: ' . $message['type'] . '<br />From: ' . $message['from'] . '<br />Text: ' . $message['text'];
  return $output;
}