You are here

function discussthis_link in Discuss This! 5

Same name and namespace in other branches
  1. 6 discussthis.module \discussthis_link()

hook_link implementation This adds the custom link to the node view

Parameters

type An identifier declaring what kind of link is being requested:

node A node object being passed in the case of node inks:

teaser A boolean flag depending on whether the node is displayed with its teaser or full form:

Return value

An array of the requested links

File

./discussthis.module, line 163

Code

function discussthis_link($type, $node = null, $teaser = false) {
  if ($type == 'node') {
    global $user;
    $links = array();
    $enabled = variable_get('discussthis_node_' . $node->type, 0);
    $display = variable_get('discussthis_teaser_' . $node->type, 2);
    if (!$enabled || $teaser && !$display) {
      return $links;
    }
    if (!$teaser && $display == 1) {
      return $links;
    }
    $topic_nid = _discussthis_get_topic($node->nid);

    // lookup a nid for the topic, if it exists (otherwise 0)
    if ($user->uid) {

      # user is logged in

      // if the topic exists, and the user has access to link to it
      if ($topic_nid && user_access('access discuss this links')) {
        $links['discussthis'] = array(
          'title' => t('Discuss This!'),
          'href' => 'node/' . $topic_nid,
        );

        // o/w if the topic doesn't exist, and the user has access to initiate topics, then
        // link to a callback page which creates a topic, then redirects to add a comment to it
      }
      if ($topic_nid == 0 && user_access('initiate discuss this topics')) {
        $links['discussthis'] = array(
          'title' => t('Discuss This!'),
          'href' => 'discussthis/new/' . $node->nid,
        );
      }
    }
    else {
      if ($topic_nid) {
        $destination = 'destination=' . drupal_urlencode("discussthis/new/" . $node->nid);
      }
      else {
        $destination = 'destination=' . drupal_urlencode("node/" . $topic_nid);
      }
      if (variable_get('user_register', 1)) {
        $links['discussthis'] = array(
          'title' => t('Login/Register to Discuss'),
          'href' => 'user',
          'query' => $destination,
        );
      }
      else {
        $links['discussthis'] = array(
          'title' => t('Login to Discuss'),
          'href' => 'user/login',
          'query' => $destination,
        );
      }
    }
    return $links;
  }
}