You are here

function privatemsg_link in Privatemsg 5.3

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

Implementation of hook_link().

File

./privatemsg.module, line 279

Code

function privatemsg_link($type, $node = NULL, $teaser = FALSE) {
  global $user;
  static $access = array();
  $links = array();
  $uid = $node->uid;
  if ($type == 'comment' && $node->nid) {
    $node = node_load($node->nid);
  }
  if (user_access('access private messages') && in_array($teaser ? 'teaser' : $type, variable_get('privatemsg_link_' . $node->type, array())) && $uid != $user->uid && $user->privatemsg_allow) {
    if (!isset($access[$uid])) {
      $author = user_load(array(
        'uid' => $uid,
      ));
      $access[$uid] = user_access('access private messages', $author) && $author->uid && $author->privatemsg_allow;
    }
    if ($access[$uid]) {
      $links['privatemsg_write_to_author'] = array(
        'title' => t('Write to author'),
        'href' => 'privatemsg/new/' . $uid,
      );
    }
  }
  return $links;
}