summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Harder2007-03-08 00:46:53 (GMT)
committer Alan Harder2007-03-08 00:46:53 (GMT)
commite953c7642156be51c1406638e2cf03b62caf31ca (patch)
tree81b5384d1d69519e22f21dd3e31f423471477f43
parent3f8f0eb7ac327c40056068cc8169a5f334a32048 (diff)
#71316 More control over where "Write to author" links appear
-rw-r--r--privatemsg.module62
1 files changed, 41 insertions, 21 deletions
diff --git a/privatemsg.module b/privatemsg.module
index f0a8cab..5b36603 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 <a href="!settings-url">content types</a> to select where these links are displayed.', array('!settings-url' => url('admin/content/types'))),
);
return system_settings_form('privatemsg_settings', $form);