diff --git a/privatemsg.module b/privatemsg.module index f0a8cab1a3ab62b9f9c95962dfc49b5edc3875d1..5b366039ccd61c1769de548f8ec0045cd1f0a6c6 100644 --- a/privatemsg.module +++ b/privatemsg.module @@ -30,13 +30,17 @@ function privatemsg_help($section) { function privatemsg_link($type, $node = 0, $main = 0) { global $user; static $access = array(); - if (user_access('access private messages') && ($type == 'node' || $type == 'comment') && variable_get("privatemsg_link_$type", 0) && $node->uid != $user->uid && (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1)) { - if (!isset($access[$node->uid])) { - $author = user_load(array('uid' => $node->uid)); - $access[$node->uid] = user_access('access private messages', $author) && $author->uid && (isset($author->privatemsg_allow) ? $author->privatemsg_allow : 1); + $uid = $node->uid; + if ($type == 'comment' && $node->nid) { + $node = node_load($node->nid); + } + if (user_access('access private messages') && in_array($main ? 'teaser' : $type, variable_get('privatemsg_link_'. $node->type, array())) && $uid != $user->uid && (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1)) { + if (!isset($access[$uid])) { + $author = user_load(array('uid' => $uid)); + $access[$uid] = user_access('access private messages', $author) && $author->uid && (isset($author->privatemsg_allow) ? $author->privatemsg_allow : 1); } - if ($access[$node->uid]) { - return array(l(t('write to author'), 'privatemsg/msgto/'. $node->uid)); + if ($access[$uid]) { + return array(l(t('write to author'), 'privatemsg/msgto/'. $uid)); } } } @@ -164,6 +168,35 @@ function privatemsg_user($type, &$edit, &$user, $category = NULL) { } } +/** + * Implementation of hook_form_alter(). + */ +function privatemsg_form_alter($form_id, &$form) { + if (isset($form['type']) && $form['type']['#value'] .'_node_settings' == $form_id) { + $link = variable_get('privatemsg_link_'. $form['#node_type']->type, array()); + $form['workflow']['privatemsg_link_'. $form['type']['#value']] = array( + '#type' => 'checkboxes', + '#title' => t('Private message "Write to author" links'), + '#weight' => 30, + 'node' => array( + '#type' => 'checkbox', + '#title' => t('Link on node'), + '#default_value' => in_array('node', $link), + ), + 'teaser' => array( + '#type' => 'checkbox', + '#title' => t('Link on teaser'), + '#default_value' => in_array('teaser', $link), + ), + 'comment' => array( + '#type' => module_exist('comment') ? 'checkbox' : 'hidden', + '#title' => t('Link on comments'), + '#default_value' => in_array('comment', $link), + ), + ); + } +} + function privatemsg_configure() { $form = array(); @@ -191,21 +224,8 @@ function privatemsg_configure() { $form['links'] = array( '#type' => 'fieldset', - '#title' => t('"Write to author" links') - ); - $form['links']['privatemsg_link_node'] = array( - '#type' => 'checkbox', - '#title' => t('Display link with posts'), - '#return_value' => 1, - '#default_value' => variable_get('privatemsg_link_node', 0), - '#description' => t('Provide a link to send private messages to users with posts they start.') - ); - $form['links']['privatemsg_link_comment'] = array( - '#type' => 'checkbox', - '#title' => t('Display link with comments'), - '#return_value' => 1, - '#default_value' => variable_get('privatemsg_link_comment', 0), - '#description' => t('Provide a link to send private messages to users with their comments.') + '#title' => t('"Write to author" links'), + '#description' => t('Edit content types to select where these links are displayed.', array('!settings-url' => url('admin/content/types'))), ); return system_settings_form('privatemsg_settings', $form);