You are here

function shoutbox_rules_add_action in Shoutbox 6.2

Adds a shout.

File

shoutbox_rules/shoutbox_rules.module, line 139

Code

function shoutbox_rules_add_action($settings) {

  // Set a basic form_state for hooks in case other modules are expecting it
  $form_state = array(
    'values' => array(
      'message' => $settings['shout'],
      'op' => 'Shout',
      'submit' => 'Shout',
      'js' => 1,
      'form_id' => 'shoutbox_add_form',
    ),
  );
  $theuser = user_load(array(
    'name' => $settings['poster'],
  ));

  // The rest of this function is basically copied from shoutbox_add_form_submit()
  // Build the shout object
  $shout = new stdClass();
  $shout->uid = $theuser->uid;
  $shout->nick = $settings['poster'];
  $shout->shout = $settings['shout'];
  $shout->moderate = 0;
  $shout->created = time();
  $shout->changed = $shout->created;
  $shout->sid = session_id();
  $shout->module = 'shoutbox';

  // Allow other modules to make changes to the shout
  shoutbox_invoke('presave', $shout, $a1 = NULL, $form_state);

  // Add shout to the database.
  drupal_write_record('shoutbox', $shout);

  // Pull shout out of db
  // We are pulling it out because thats the only way to get the shout_id
  $shout = db_fetch_object(db_query("SELECT * FROM {shoutbox} WHERE uid = %d AND shout = '%s' AND created = %d AND sid = '%s'", $shout->uid, $shout->shout, $shout->created, $shout->sid));

  // Alert other modules about the new shout via hook
  shoutbox_invoke('insert', $shout, $a1 = NULL, $form_state);
  return;
}