function shouts_shout_form_submit in Heartbeat 6.4
Same name and namespace in other branches
- 6.3 modules/shouts/shouts.module \shouts_shout_form_submit()
User submitted the shoutform, save the shout.
1 string reference to 'shouts_shout_form_submit'
- shouts_menu in modules/
shouts/ shouts.module - Implementation of hook_menu().
File
- modules/
shouts/ shouts.module, line 267 - Gives the possibility to the user to shout a message.
Code
function shouts_shout_form_submit($form = array(), &$form_state = array()) {
$ahah = empty($form);
global $user;
$uid = $user->uid;
// Check the token.
$token = 'heartbeat_shout_post_' . $uid;
$token_value = $ahah ? $_POST['heartbeat_shout_token'] : $form_state['values']['heartbeat_shout_token'];
if (!drupal_valid_token($token_value, $token)) {
drupal_json(array(
'status' => FALSE,
'data' => t('Access denied'),
));
exit;
}
$message = $ahah ? $_POST['shout'] : $form_state['values']['shout'];
if (!user_access('make shout') || empty($message)) {
drupal_json(array(
'status' => FALSE,
'data' => t('No message recorded'),
));
exit;
}
$success = db_query("INSERT INTO {shouts} (uid, message, time) VALUES (%d, '%s', '%s')", $uid, $message, date('Y-m-d H:i:s'));
$shout_id = db_last_insert_id('shouts', 'shout_id');
$shout = shout_load($shout_id);
if (!empty($shout)) {
// Give other modules a chance to hook.
module_invoke_all('shout', $user, $shout);
// Let rules know there has been a shout event
if (module_exists('rules')) {
rules_invoke_event('shout_post', $user, $shout);
}
if ($ahah) {
drupal_json(array(
'status' => TRUE,
'data' => theme('shoutform_message', $message, true, true, date('Y-m-d H:i:s')),
));
exit;
}
else {
drupal_set_message(t('Shout has been posted.'));
}
return;
}
if ($ahah) {
drupal_json(array(
'status' => TRUE,
'data' => 'error',
));
exit;
}
else {
drupal_set_message(t('Error while posting shout.'));
}
}