function shoutbox_add_form_submit in Shoutbox 6.2
Same name and namespace in other branches
- 5 shoutbox.module \shoutbox_add_form_submit()
- 6 shoutbox.module \shoutbox_add_form_submit()
- 7.2 shoutbox.module \shoutbox_add_form_submit()
- 7 shoutbox.module \shoutbox_add_form_submit()
Handles submission of a shout. Handles both ajax submission and regular form submission.
File
- ./
shoutbox.module, line 429 - Shout box module displays a block for users to create short messages for the whole site. Uses AHAH to update the database and display content.
Code
function shoutbox_add_form_submit($form, &$form_state) {
global $user;
// Check user's permission and set shout visibility status accordingly.
if (!_shoutbox_user_access('post shouts without approval')) {
$moderate = 1;
}
else {
$moderate = 0;
}
// Build the shout object
$shout = new stdClass();
$shout->uid = $user->uid;
$shout->nick = $user->name ? $user->name : variable_get('anonymous', 'Anonymous');
$shout->shout = $form_state['values']['message'];
$shout->moderate = $moderate;
$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 and display.
// We are pulling it out because thats the only way to get the shout_id
// which is need for edit, hook, etc.
$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);
// Check is Javascript was enabled
if ($_POST['js']) {
exit;
}
else {
// Return as usual
return;
}
}