You are here

function nodejs_subscribe_node_view in Node.js integration 7

Same name and namespace in other branches
  1. 6 nodejs_subscribe/nodejs_subscribe.module \nodejs_subscribe_node_view()

Implements hook_node_view().

File

nodejs_subscribe/nodejs_subscribe.module, line 211

Code

function nodejs_subscribe_node_view($node, $view_mode) {
  global $user;

  // If node allows nodejs subscriptions and user has permission to subscribe,
  // then provide "Subscribe" or "Unsubscribe" links.
  if (isset($node->nodejs_subscribe) && $node->nodejs_subscribe && user_access('nodejs subscribe to node') && in_array($view_mode, array(
    'full',
    'teaser',
  ))) {
    $links = array();
    $node_title_stripped = strip_tags($node->title);
    if (nodejs_subscribe_is_user_subscribed_to_node($user->uid, $node->nid)) {
      $links['nodejs-subscribe-unsubscribe-node'] = array(
        'title' => t('Unsubscribe'),
        'href' => "nodejs/unsubscribe/{$node->nid}",
        'attributes' => array(
          'class' => array(
            'nodejs-subscribe-node-link',
          ),
          'title' => t('Unsubscribe to @title', array(
            '@title' => $node_title_stripped,
          )),
        ),
      );
    }
    else {
      $links['nodejs-subscribe-subscribe-node'] = array(
        'title' => t('Subscribe'),
        'href' => "nodejs/subscribe/{$node->nid}",
        'attributes' => array(
          'class' => array(
            'nodejs-subscribe-node-link',
          ),
          'title' => t('Subscribe to @title', array(
            '@title' => $node_title_stripped,
          )),
        ),
      );
    }
    $node->content['links']['nodejs_subscribe'] = array(
      '#theme' => 'links__node__nodejs_subscribe',
      '#links' => $links,
      '#attributes' => array(
        'class' => array(
          'links',
          'inline',
        ),
      ),
    );
  }
}