You are here

function print_mail_form in Printer, email and PDF versions 7

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. 5.x print_mail/print_mail.inc \print_mail_form()

Menu callback for the send by email form.

2 string references to 'print_mail_form'
print_mail_menu in print_mail/print_mail.module
Implements hook_menu().
print_mail_mollom_form_info in print_mail/print_mail.module
Implemenents hook_mollom_form_info().

File

print_mail/print_mail.inc, line 23

Code

function print_mail_form($form, &$form_state) {
  global $user;

  // Remove the printmail/ prefix
  $path_arr = explode('/', $_GET['q']);
  unset($path_arr[0]);
  $path = filter_xss(implode('/', $path_arr));
  if (empty($path)) {

    // If no path was provided, let's try to generate a page for the referer
    global $base_url;
    $ref = $_SERVER['HTTP_REFERER'];
    $path = preg_replace("!^{$base_url}/!", '', $ref);
    if ($path === $ref || empty($path)) {
      $path = variable_get('site_frontpage', 'node');
    }
    drupal_goto(PRINTMAIL_PATH . '/' . $path);
  }
  elseif (ctype_digit($path_arr[1])) {
    if (drupal_lookup_path('source', $path)) {

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

      // normal nid
      $path = 'node/' . $path;
    }
  }
  else {
    $path = drupal_get_normal_path($path);
  }

  // Handle the query
  $query = $_GET;
  unset($query['q']);
  $print_mail_hourly_threshold = variable_get('print_mail_hourly_threshold', PRINT_MAIL_HOURLY_THRESHOLD);
  if (!user_access('send unlimited emails') && !flood_is_allowed('print_mail', $print_mail_hourly_threshold)) {
    $form['flood'] = array(
      '#type' => 'markup',
      '#markup' => '<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();
  $cid = isset($_GET['comment']) ? (int) $_GET['comment'] : NULL;
  $title = _print_get_title($path);
  if (count($form_state['input']) == 0) {
    $nodepath = drupal_get_normal_path($path);
    db_merge('print_mail_page_counter')
      ->key(array(
      'path' => $nodepath,
    ))
      ->fields(array(
      'totalcount' => 1,
      'timestamp' => REQUEST_TIME,
    ))
      ->expression('totalcount', 'totalcount + 1')
      ->execute();
  }
  $form['path'] = array(
    '#type' => 'value',
    '#value' => $path,
  );
  $form['query'] = array(
    '#type' => 'value',
    '#value' => $query,
  );
  $form['cid'] = array(
    '#type' => 'value',
    '#value' => $cid,
  );
  $form['title'] = array(
    '#type' => 'value',
    '#value' => $title,
  );
  $form['fld_from_addr'] = array(
    '#type' => 'textfield',
    '#title' => t('Your email'),
    '#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)) {

    // To prevent useless translation strings, try to translate only non-node titles
    if (drupal_substr($path, 0, 5) != 'node/') {
      $title = t($title);
    }
    $form['fld_title'] = array(
      '#type' => 'item',
      '#title' => t('Page to be sent'),
      '#markup' => l($title, $path, array(
        'attributes' => array(
          'title' => t('View page'),
        ),
        'query' => $query,
      )),
    );
  }
  $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 email'),
  );
  $form['btn_cancel'] = array(
    '#name' => 'cancel',
    '#type' => 'submit',
    '#value' => t('Cancel'),
  );
  if ($user->uid != 0) {
    $user_name = check_plain(strip_tags(theme('username', array(
      'account' => $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;
}