You are here

function privatemsg_link in Privatemsg 6.2

Same name and namespace in other branches
  1. 5.3 privatemsg.module \privatemsg_link()
  2. 5 privatemsg.module \privatemsg_link()

Implements hook_link().

File

./privatemsg.module, line 2408
Allows users to send private messages to other users.

Code

function privatemsg_link($type, $object, $teaser = FALSE) {
  global $user;
  static $nodes = array();
  $links = array();
  if (!isset($nodes[$object->uid])) {
    if ($type == 'node') {
      $nodes[$object->nid] = $object;
    }
    elseif ($type == 'comment') {
      $nodes[$object->nid] = node_load($object->nid);
    }
  }
  $types = array_filter(variable_get('privatemsg_link_node_types', array()));
  $url = privatemsg_get_link(privatemsg_user_load($object->uid));
  if ($type == 'node' && in_array($object->type, $types) && !empty($url) && ($teaser == FALSE || variable_get('privatemsg_display_on_teaser', 1))) {
    $links['privatemsg_link'] = array(
      'title' => t('Send author a message'),
      'href' => $url . '/' . t('Message regarding @node', array(
        '@node' => $object->title,
      )),
      'query' => drupal_get_destination(),
      'attributes' => array(
        'class' => 'privatemsg-send-link privatemsg-send-link-node',
      ),
    );
  }
  if ($type == 'comment' && in_array($nodes[$object->nid]->type, $types) && !empty($url) && variable_get('privatemsg_display_on_comments', 0)) {
    $links['privatemsg_link'] = array(
      'title' => t('Send private message'),
      'href' => $url . '/' . t('Message regarding @comment', array(
        '@comment' => $object->subject,
      )),
      'query' => drupal_get_destination(),
      'attributes' => array(
        'class' => 'privatemsg-send-link privatemsg-send-link-comment',
      ),
    );
  }
  return $links;
}