'fieldset', '#title' => t('Invite people to this @type', array('@type' => $node->type)), '#description' => '', '#collapsed' => TRUE, '#collapsible' => TRUE, ); } if (variable_get('node_invite_set_email', TRUE) || $user->uid == 0) { $form['invite']['your_name'] = array( '#title' => t('Your Name'), '#type' => 'textfield', '#default_value' => $user->name, '#weight' => 0, ); $form['invite']['your_email'] = array( '#title' => t('Your E-mail Address'), '#type' => 'textfield', '#default_value' => $user->mail, '#weight' => 1, ); } else { $form['invite']['your_name'] = array( '#type' => 'value', '#value' => $user->name, ); $form['invite']['your_email'] = array( '#type' => 'value', '#value' => $user->mail, ); } $form['invite']['personal_message'] = array( '#weight' => 2, ); $form['invite']['personal_message']['message'] = array( '#type' => 'textarea', '#title' => t('Personal Message'), '#description' => t('Your personal message is going to be HTML formatted if you are using the HTMLMail module. In addition, the personal message can take advantage of tokens. See Token Help below.'), ); $form['invite']['personal_message']['node_invite_tokens'] = array( '#type' => 'fieldset', '#title' => ("Token Help"), '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => "

Not all tokens will be available. The following lists all tokens known to Drupal. The list of available tokens will depend on the type of node to which you are inviting people.

" . theme('token_help', 'all'), ); if (!variable_get('node_invite_disable_users', 0)) { $form['invite']['users'] = array( '#type' => 'textfield', '#title' => t('Users to invite'), '#autocomplete_path' => 'node_invite/user_autocomplete', '#description' => t('Enter the list of users you would like to invite, separated by commas'), '#weight' => 4, ); } if (!variable_get('node_invite_disable_email', 0)) { $form['invite']['emails'] = array( '#title' => t('Email Addresses for Delivery'), '#type' => 'textarea', '#description' => t('One recipient per line please. Recipients can be entere as Name|Email or just an email address.'), '#weight' => 5, ); } $form['invite']['submit'] = array( '#type' => 'submit', '#value' => t('Send Emails'), '#weight' => 20, ); $form['node'] = array( '#type' => 'value', '#value' => $node, ); return $form; } function node_invite_send_validate($form, &$form_state) { // validate sender if (!valid_email_address($form_state['values']['your_email'])) { form_set_error('your_email', t('!email is not a valid email address', array('!email' => $form_state['values']['your_email']))); } // validate recipients $emails = explode("\n", $form_state['values']['emails']); $emails = array_filter($emails); foreach ($emails as $email) { $split = preg_split('/\s*\|\s*/', $email); if (count($split) == 2) { $email = $split[1]; } $email = trim($email); if ($email != '' && !valid_email_address($email)) { form_set_error('emails', t('%email is not a valid email address', array('%email' => $email))); } } // Validate all users and store their uids in the 'storage' field to be used // by the submit function. $users = preg_split('/ *, */', $form_state['values']['users']); $users = array_filter($users); $form_state['storage']['users'] = array(); foreach ($users as $user) { $query = "SELECT uid FROM {users} WHERE LOWER(name) = LOWER('%s')"; $uid = db_result(db_query($query, trim($user))); if (!$uid) { form_set_error('users', t('%user is not a valid username', array('%user' => $user))); } $form_state['storage']['users'][] = $uid; } // Has anyone been added to the invite? if (!count($emails) && !count($users)) { form_set_error('emails', t("No one has been added to the invite.")); } } function node_invite_send_submit($form, &$form_state) { global $user; $node = $form_state['values']['node']; // Create the email address based invites $emails = explode("\n", $form_state['values']['emails']); // Remove any empty items $emails = array_filter($emails); $invites = array(); if (is_array($emails)) { foreach ($emails as $email) { $split = preg_split('/\s*\|\s*/', $email); $recip_name = $email; // Set name = email unless a name is set $recip_mail = $email; if (count($split) == 2) { $email = trim($split[0]) . ' <'. trim($split[1]) . '>'; $recip_name = $split[0]; $recip_mail = $split[1]; } $email = trim($email); // Save the invite $account = user_load(array('mail' => $recip_mail)); $params = array( 'nid' => $node->nid, 'email_invitee' => $recip_mail, 'name_invitee' => $recip_name, 'uid_invitee' => $account ? $account->uid : 0, 'uid_inviter' => $user->uid, 'status' => NODE_INVITE_NEW, 'inviter_custom_name' => $form_state['values']['your_name'], 'inviter_custom_email' => $form_state['values']['your_email'], 'personal_message' => $form_state['values']['message'], ); $invites[] = node_invite_save(NULL, $params); } } // Create the user account based invites // TODO: If a user was invited in both the email and user fields, then they // will receive two invites. We should probably filter them out of the // email invites. if (is_array($form_state['storage']['users'])) { foreach ($form_state['storage']['users'] as $uid) { $account = user_load($uid); $params = array( 'nid' => $node->nid, 'email_invitee' => $account->mail, 'name_invitee' => $account->name, 'uid_invitee' => $account->uid, 'uid_inviter' => $user->uid, 'status' => NODE_INVITE_NEW, 'inviter_custom_name' => $form_state['values']['your_name'], 'inviter_custom_email' => $form_state['values']['your_email'], 'personal_message' => $form_state['values']['message'], ); $invites[] = node_invite_save(NULL, $params); } } // Send out the emails $send_count = 0; foreach ($invites as $invite) { // Set the tokens to be replaced in the email. node_invite_specific_info($invite, $node); if (variable_get('node_invite_set_email', TRUE) || $user->uid == 0) { $node->invite_specific_info['inviter-name'] = $form_state['values']['your_name']; $node->invite_specific_info['inviter-mail'] = $form_state['values']['your_email']; } // Send the invite node_invite_send_mail($invite, $node); $send_count++; } // send them somewhere... back to the node! drupal_set_message($send_count . ' messages sent'); unset($form_state['storage']); $form_state['redirect'] = "node/" . $node->nid; }