diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2012-09-24 18:31:41 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2012-09-24 18:31:41 -0300 |
commit | f60cdd73427b6920950876ad4981e8e71402e8cf (patch) | |
tree | cc2a109fbc7418a29185eb991b45611c7f3553f4 | |
parent | aabc235e31c028c30c899b495871f47d8719aa3d (diff) | |
download | reminder-f60cdd73427b6920950876ad4981e8e71402e8cf.tar.gz reminder-f60cdd73427b6920950876ad4981e8e71402e8cf.tar.bz2 |
Refactoring reminder_node_submit()
-rw-r--r-- | reminder.module | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/reminder.module b/reminder.module index 60a24ba..b370530 100644 --- a/reminder.module +++ b/reminder.module @@ -242,6 +242,10 @@ function reminder_form(&$node) { * @todo * Throttling settings to avoid SPAM: max posts per * hour and max recipients per post. + * + * Validate name and email if not registered user. + * Date and interval validation. + * Test all fields. */ function reminder_validate($node, $form, &$form_state) { if ($form['type']['#value'] == 'reminder') { @@ -253,8 +257,8 @@ function reminder_validate($node, $form, &$form_state) { * Implementation of hook_node_submit() * * @todo - * Refactor. * Date, remind and subscribe widgets. + * Update subscribers, removing old ones. */ function reminder_node_submit($node, $form, &$form_state) { // No preview available. @@ -275,6 +279,7 @@ function reminder_node_submit($node, $form, &$form_state) { if ($node->nid == NULL) { global $user; + $action = 'create'; // Save basic data. node_save($node); @@ -311,41 +316,13 @@ function reminder_node_submit($node, $form, &$form_state) { } $query = db_insert('reminder_subscriptions')->fields($values); - - // Send an email message. - //if ($form_state['values']['email_notification']) { - if (TRUE) { - $mail = ""; - if ($user->uid > 0) { - $mail = $user->mail; - } - elseif (valid_email_address($form_state['values']['anonym']['user_email'])) { - $mail = $form_state['values']['anonym']['user_email']; - } - - if ($mail != "") { - if ($user->uid > 0) { - $name = $user->name; - } - elseif (isset($form_state['values']['anonym']['user_name'])) { - $name = $form_state['values']['anonym']['user_name']; - } - - $params = array( - "name" => $name, - "reminder_url" => $reminder_url, - "admin_url" => $admin_url, - ); - drupal_mail('reminder', 'create_new_reminder', $mail, language_default(), $params); - } - - } } else { // Fetch existing options. $reminder = reminder_get_reminder($node->nid); $reminder_url = $reminder['url']; $admin_url = $reminder['admin_url']; + $action = 'update'; // Update basic data. node_save($node); @@ -362,6 +339,17 @@ function reminder_node_submit($node, $form, &$form_state) { // TODO: Update subscribers, removing old ones. } + $mail = ($user->uid > 0) ? $mail = $user->mail : $form_state['values']['anonym']['user_email']; + $name = ($user->uid > 0) ? $user->name : $form_state['values']['anonym']['user_name']; + + // Send message to reminder owner + drupal_mail('reminder', $action .'_reminder', $mail, language_default(), array( + "name" => $name, + "reminder_url" => $reminder_url, + "admin_url" => $admin_url, + ) + ); + // Send reminder now. if (isset($form_state['reminder_options']['now']) && $form_state['reminder_options']['now'] != 0) { reminder_send($node->nid); @@ -402,7 +390,9 @@ function reminder_mail($key, &$message, $params) { $message['subject'] .= str_replace(array("\r", "\n"), '', $subject); $message['body'][] = drupal_html_to_text($body); - if ($key == 'create_new_reminder') { + if ($key == 'create_reminder') { + } + else if ($key == 'update_reminder') { } } |