You are here

function print_mail_form in Printer, email and PDF versions 5.x

Same name and namespace in other branches
  1. 5.4 print_mail/print_mail.inc \print_mail_form()
  2. 5.3 print_mail/print_mail.inc \print_mail_form()
  3. 6 print_mail/print_mail.inc \print_mail_form()
  4. 7.2 print_mail/print_mail.inc \print_mail_form()
  5. 7 print_mail/print_mail.inc \print_mail_form()

Menu callback for the send by e-mail form.

1 string reference to 'print_mail_form'
print_mail_menu in print_mail/print_mail.module
Implementation of hook_menu().

File

print_mail/print_mail.inc, line 23

Code

function print_mail_form($form_state) {
  global $user;
  $print_mail_hourly_threshold = variable_get('print_mail_hourly_threshold', PRINT_MAIL_HOURLY_THRESHOLD);
  if (!user_access('administer print') && !flood_is_allowed('print_mail', $print_mail_hourly_threshold)) {
    $form['flood'] = array(
      '#type' => 'markup',
      '#value' => '<p>' . format_plural($print_mail_hourly_threshold, 'You cannot send more than 1 message per hour. Please try again later.', 'You cannot send more than @count messages per hour. Please try again later.') . '</p>',
    );
    return $form;
  }
  $print_mail_teaser_default = variable_get('print_mail_teaser_default', PRINT_MAIL_TEASER_DEFAULT_DEFAULT);
  $print_mail_teaser_choice = variable_get('print_mail_teaser_choice', PRINT_MAIL_TEASER_CHOICE_DEFAULT);
  $form = array();

  // Remove the printmail/ prefix
  $path = explode('/', $_GET['q']);
  unset($path[0]);
  $path = implode('/', $path);
  if (is_numeric($path)) {
    if (drupal_lookup_path('source', $path)) {

      // This is a numeric alias
      $path = drupal_get_normal_path($path);
    }
    else {

      // normal nid
      $path = 'node/' . $path;
    }
  }
  $cid = isset($_GET['comment']) ? (int) $_GET['comment'] : NULL;
  $title = _print_get_title($path);
  if (count($form_state['post']) == 0) {
    $nodepath = drupal_get_normal_path($path);
    db_query("UPDATE {print_mail_page_counter} SET totalcount = totalcount + 1, timestamp = %d WHERE path = '%s'", time(), $nodepath);

    // If we affected 0 rows, this is the first time viewing the node.
    if (!db_affected_rows()) {

      // We must create a new row to store counters for the new node.
      db_query("INSERT INTO {print_mail_page_counter} (path, totalcount, timestamp) VALUES ('%s', 1, %d)", $nodepath, time());
    }
  }
  $form['path'] = array(
    '#type' => 'value',
    '#value' => $path,
  );
  $form['cid'] = array(
    '#type' => 'value',
    '#value' => $cid,
  );
  $form['title'] = array(
    '#type' => 'value',
    '#value' => $title,
  );
  $form['fld_from_addr'] = array(
    '#type' => 'textfield',
    '#title' => t('Your e-mail'),
    '#size' => 62,
    '#required' => TRUE,
  );
  $form['fld_from_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Your name'),
    '#size' => 62,
  );
  $form['txt_to_addrs'] = array(
    '#type' => 'textarea',
    '#title' => t('Send to'),
    '#rows' => 3,
    '#resizable' => FALSE,
    '#description' => t('Enter multiple addresses separated by commas and/or different lines.'),
    '#required' => TRUE,
  );
  $form['fld_subject'] = array(
    '#type' => 'textfield',
    '#title' => t('Subject'),
    '#size' => 62,
    '#required' => TRUE,
  );
  if (!empty($title)) {
    $form['fld_title'] = array(
      '#type' => 'item',
      '#title' => t('Page to be sent'),
      '#value' => l($title, $path, array(
        'attributes' => array(
          'title' => t('View page'),
        ),
      )),
    );
  }
  $form['fld_send_option'] = array(
    '#type' => 'select',
    '#title' => t('Send page as'),
    '#default_value' => variable_get('print_mail_send_option_default', PRINT_MAIL_SEND_OPTION_DEFAULT),
    '#options' => array(
      'sendlink' => t('Link'),
      'sendpage' => t('Inline HTML'),
    ),
  );
  if (class_exists('Mail_mime')) {
    $form['fld_send_option']['#options']['inline-attachment'] = t('Inline HTML with Attachment');
    $form['fld_send_option']['#options']['plain-attachment'] = t('Plain Text with Attachment');
  }
  $form['txt_message'] = array(
    '#type' => 'textarea',
    '#title' => t('Your message'),
    '#rows' => 6,
    '#required' => TRUE,
  );
  if ($print_mail_teaser_choice) {
    $form['chk_teaser'] = array(
      '#type' => 'checkbox',
      '#title' => t('Send only the teaser'),
      '#default_value' => $print_mail_teaser_default,
    );
  }
  else {
    $form['chk_teaser'] = array(
      '#type' => 'value',
      '#value' => $print_mail_teaser_default,
    );
  }
  $form['btn_submit'] = array(
    '#name' => 'submit',
    '#type' => 'submit',
    '#value' => t('Send e-mail'),
  );
  $form['btn_clear'] = array(
    '#type' => 'markup',
    '#value' => '<input type="reset" name="clear" id="edit-btn-clear" value="' . t('Clear form') . '" class="form-submit" />',
  );
  $form['btn_cancel'] = array(
    '#name' => 'cancel',
    '#type' => 'submit',
    '#value' => t('Cancel'),
  );
  if ($user->uid != 0) {
    $user_name = check_plain(strip_tags(theme('username', $user)));
    $form['fld_from_addr']['#default_value'] = $user->mail;
    $form['fld_from_addr']['#disabled'] = TRUE;
    $form['fld_from_addr']['#value'] = $user->mail;
    $form['fld_from_name']['#default_value'] = $user_name;
  }
  else {
    $user_name = t('Someone');
  }
  $site_name = variable_get('site_name', t('an interesting site'));
  $print_mail_text_subject = filter_xss(variable_get('print_mail_text_subject', t('!user has sent you a message from !site')));
  $form['fld_subject']['#default_value'] = t($print_mail_text_subject, array(
    '!user' => $user_name,
    '!site' => $site_name,
    '!title' => $title,
  ));
  $print_mail_text_content = filter_xss(variable_get('print_mail_text_content', ''));
  $form['txt_message']['#default_value'] = t($print_mail_text_content);
  return $form;
}