You are here

function quotes_node_view in Quotes 7

Implements hook_node_view().

File

./quotes.module, line 844
The quotes module allows users to maintain a list of quotes that can be displayed in any number of administrator-defined quote blocks.

Code

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

  // Are we in a quotes_block.
  $in_block = isset($node->in_block) && $node->in_block;
  if ($node->type == 'quotes' && $view_mode == 'full') {
    $format = variable_get('quotes_format', filter_default_format());
    $variables['node'] = $node;

    // Format to use for author and citation.
    $variables['format'] = $format;

    // Add author's bio to top of page if enabled and present.
    if (variable_get('quotes_author_bio', FALSE) >= 1 && !empty($node->quotes_bio)) {
      if (!$in_block && variable_get('quotes_bio_set', FALSE) == 0) {
        $node->content['quotes_bio'] = array(
          '#prefix' => '<div class="quotes-header-bio">',
          '#suffix' => '</div>',
          '#markup' => check_markup($node->quotes_bio, $format, $node->language, FALSE),
        );
        variable_set('quotes_bio_set', TRUE);
      }
    }
    if (arg(0) == 'quotes' and arg(1) == 'author') {
      $node->title = '';
    }

    // Plain text title for block.
    if ($in_block and $node->show_titles == 2) {

      // @todo - Needs template to do this or to use
      // an extra field to overwrite node title. Interesting!
    }

    // Add Author if present.
    theme_quotes_author($variables);
    $node = $variables['node'];

    // Add citation if present.
    $variables['node'] = $node;
    theme_quotes_citation($variables);
    $node = $variables['node'];

    // Now the links.
    if (arg(0) == 'quotes' && arg(1) == 'author') {

      // Only show this link on authors page.
      if (!$in_block && variable_get('quotes_edit_link', TRUE)) {
        if (user_access('edit own quotes') && $node->uid == $user->uid || user_access('administer quotes')) {
          $links['quotes_editlink'] = array(
            'title' => check_plain('Edit'),
            'href' => 'node/' . $node->nid . '/edit',
            'attributes' => array(
              'class' => array(
                'quotes-edit-link',
              ),
              'title' => check_plain('Edit'),
            ),
          );
          $node->content['links']['quotes'] = array(
            '#theme' => 'links__node__quotes',
            '#links' => $links,
            '#attributes' => array(
              'class' => array(
                'links',
                'inline',
              ),
            ),
          );
        }
      }
    }
    if ($in_block) {

      // Are we changing the more link text.
      if ($in_block && $node->more_text) {
        $links['view_link'] = array(
          'title' => check_plain($node->more_text),
          'href' => 'quotes',
          'attributes' => array(
            'class' => array(
              'quotes-more-link',
            ),
            'title' => check_plain($node->more_text),
          ),
        );
        $node->content['links']['quotes'] = array(
          '#theme' => 'links__node__quotes',
          '#links' => $links,
          '#attributes' => array(
            'class' => array(
              'links',
              'inline',
            ),
          ),
        );
      }
    }

    // Is the comments installed and enambled, if so do we wish to display
    // a link to access them?
    if (module_exists('comment') && $in_block && $node->comment == COMMENT_NODE_OPEN && !empty($node->view_text)) {
      $links['view_link'] = array(
        'title' => $node->view_text,
        'href' => 'node/' . $node->nid,
        'attributes' => array(
          'class' => 'quotes-view-link',
        ),
      );
      $node->content['links']['quotes'] = array(
        '#theme' => 'links__node__quotes',
        '#links' => $links,
        '#attributes' => array(
          'class' => array(
            'links',
            'inline',
          ),
        ),
      );
    }
  }

  // RSS Feeds.
  if ($view_mode != 'rss') {
    if ($node->type == 'quotes' && !(arg(0) == 'quotes' && arg(1) == $node->uid)) {
      $name = $node->uid ? $node->name : variable_get('anonymous', t('Anonymous'));
      $links = array();
      if (variable_get('quotes_showlink', TRUE)) {
        if ($node->uid != $user->uid) {

          // Get the menu title.
          $menu_info = menu_get_item('quotes');
          $menu_title = $menu_info['title'];
          $links['quotes_usernames_quotes'] = array(
            'title' => t("!username's quotes", array(
              '!username' => format_username($node),
            )),
            'href' => "quotes/{$node->uid}",
            'attributes' => array(
              'title' => t("Read !username's latest quotes entries.", array(
                '!username' => format_username($node),
              )),
            ),
          );
          $node->content['links']['quotes'] = array(
            '#theme' => 'links__node__quotes',
            '#links' => $links,
            '#attributes' => array(
              'class' => array(
                'links',
                'inline',
              ),
            ),
          );
        }
      }
    }
  }
}