diff -urp print/print_mail/print_mail.inc print-tokens/print_mail/print_mail.inc --- print/print_mail/print_mail.inc 2009-10-03 12:52:10.000000000 -0400 +++ print-tokens/print_mail/print_mail.inc 2009-10-23 22:28:00.750000000 -0400 @@ -43,10 +43,17 @@ function print_mail_form($form_state) { $path = 'node/'. $path; } $cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL; - $title = _print_get_title($path); + + // Determine page type and access node type if applicable + $nodetype = ''; + $nodepath = drupal_get_normal_path($path); + $nodepaths = explode('/', $nodepath); + if ($nodepaths[0] == 'node') { + $node = node_load(substr($nodepath, 5)); + $nodetype = $node->type; + } 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()) { @@ -55,22 +62,33 @@ function print_mail_form($form_state) { } } + // Define replacement tokens for default text + $print_tokens = array( + '!user' => $user->uid != 0 ? check_plain(strip_tags(theme('username', $user))) : t('Someone'), + '!site' => variable_get('site_name', t('an interesting site')), + '!title' => _print_get_title($path), + ); + $form['path'] = array('#type' => 'value', '#value' => $path); $form['cid'] = array('#type' => 'value', '#value' => $cid); $form['fld_from_addr'] = array( '#type' => 'textfield', '#title' => t('Your e-mail'), + '#default_value' => $user->uid != 0 ? $user->mail : '', + '#disabled' => $user->uid != 0 ? TRUE : FALSE, '#size' => 62, ); $form['fld_from_name'] = array( '#type' => 'textfield', '#title' => t('Your name'), + '#default_value' => $user->uid != 0 ? $print_tokens['!user'] : '', '#size' => 62, ); $form['txt_to_addrs'] = array( '#type' => 'textarea', '#title' => t('Send to'), + '#default_value' => variable_get('print_mail_text_to_'. $nodetype, ''), '#rows' => 3, '#resizable' => FALSE, '#description' => t('Enter multiple addresses separated by commas and/or different lines.'), @@ -78,16 +96,20 @@ function print_mail_form($form_state) { $form['fld_subject'] = array( '#type' => 'textfield', '#title' => t('Subject'), + '#default_value' => variable_get('print_mail_text_subject_'. $nodetype, + variable_get('print_mail_text_subject', t('!user has sent you a message from !site', $print_tokens)) + ), '#size' => 62, ); $form['fld_title'] = array( '#type' => 'item', '#title' => t('Page to be sent'), - '#value' => l($title, $path, array('attributes' => array('title' => t('View page')))), + '#value' => l($print_tokens['!title'], $path, array('attributes' => array('title' => t('View page')))), ); $form['txt_message'] = array( '#type' => 'textarea', '#title' => t('Your message'), + '#default_value' => variable_get('print_mail_text_message_'. $nodetype, variable_get('print_mail_text_content', '')), '#rows' => 6, ); @@ -117,21 +139,12 @@ function print_mail_form($form_state) { '#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'); + // Token support + if (module_exists('token')) { + $form['txt_to_addrs']['#default_value'] = token_replace($form['txt_to_addrs']['#default_value'], 'node', $node); + $form['fld_subject']['#default_value'] = token_replace($form['fld_subject']['#default_value'], 'node', $node); + $form['txt_message']['#default_value'] = token_replace($form['txt_message']['#default_value'], 'node', $node); } - $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; } diff -urp print/print_mail/print_mail.module print-tokens/print_mail/print_mail.module --- print/print_mail/print_mail.module 2009-10-15 19:43:28.000000000 -0400 +++ print-tokens/print_mail/print_mail.module 2009-10-23 22:06:55.937500000 -0400 @@ -256,6 +256,37 @@ function print_mail_form_alter(&$form, $ $form['print']['print_mail_display']['#default_value'] = variable_get('print_mail_display_'. $form['#node_type']->type, PRINT_TYPE_SHOW_LINK_DEFAULT); $form['print']['print_mail_display_comment']['#default_value'] = variable_get('print_mail_display_comment_'. $form['#node_type']->type, PRINT_TYPE_COMMENT_LINK_DEFAULT); $form['print']['print_mail_display_urllist']['#default_value'] = variable_get('print_mail_display_urllist_'. $form['#node_type']->type, PRINT_TYPE_URLLIST_DEFAULT); + + // Node Type Specific Mail Text Settings + $form['print']['mail'] = array ( + '#type' => 'fieldset', + '#title' => t('E-mail text settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['print']['mail']['print_mail_text_to'] = array ( + '#type' => 'textfield', + '#title' => t('Recipients'), + '#default_value' => variable_get('print_mail_text_to_'. $form['#node_type']->type, ''), + '#size' => 60, + '#maxlength' => 250, + '#description' => t('A comma-separated list of recipient e-mail addresses and / or tokens.'), + ); + $form['print']['mail']['print_mail_text_subject'] = array ( + '#type' => 'textfield', + '#title' => t('Subject'), + '#default_value' => variable_get('print_mail_text_subject_'. $form['#node_type']->type, ''), + '#size' => 60, + '#maxlength' => 250, + '#description' => t('A string of text and / or tokens to be used as the default e-mail subject.'), + ); + $form['print']['mail']['print_mail_text_message'] = array ( + '#type' => 'textarea', + '#title' => t('Message'), + '#default_value' => variable_get('print_mail_text_message_'. $form['#node_type']->type, ''), + '#rows' => 3, + '#description' => t('A string of text and / or tokens to be used as the default e-mail message.'), + ); } else { $node = $form['#node'];